Home Writing

til / migrate dotfiles to lua

I was anxious about this at first. It felt like a lot of work, and I had my environment working just the way I wanted. But, I decided to take a leap of faith and started converting to Lua. New year, new me, maybe? In hindsight, I regret not making this update sooner because it has rekindled my love for Neovim.

Since it was already a big undertaking, I decided to make it bigger by starting from a clean slate. Rethink every plugin and setting I had accumulated over the years. I don’t even remember why I added some things in the first place. I also wanted the revamped list of plugins to be written in Lua whenever possible. This meant that most of my plugins needed to change.

Package management #

vim-plugpacker.nvimlazy.nvim

The first thing I needed to find was a new package manager. I had settled on packer.nvim which was easy to get started with and it felt great.

But, a video popped up in my YouTube recommendations. It migrated to lazy.nvim which was released at the end of 2022. lazy.nvim features easier lazy loading and performance improvements out of the box. I got curious if I would see any speed gains. Luckily, lazy.nvim’s API is similar to packer.nvim.

I used hyperfine to benchmark the difference in startup time between my shiny new packer.nvim setup and lazy.nvim. Turns out, lazy.nvim can make a huge difference.

Computer packer.nvim lazy.nvim
MacBook Pro M1 (2020) 729.2 ms 80.9 ms
MacBook Pro M1 Pro (2021) 245.7 ms 42.6 ms

It’s also worth noting that lazy.nvim shaved almost 200 ms off the startup time on the 2020 M1 without any configuration. The speeds listed above for lazy.nvim are with lazy loading enabled for some plugins.

Other notable package changes #

Here are some other packages written in Lua that I’ve started using.

Highlighting #

vim-polyglotnvim-treesitter

Tree-sitter is a faster and, arguably, better syntax parser than traditional regex parsing. It also comes integrated in Neovim. This talk by tree-sitter’s creator Max Brunsfeld is a great introduction to what it is and how it works.

The change had implications on my color scheme. I had a fork of the Night Owl theme, which for me was the perfect theme. However, it didn’t work with tree-sitter and I would rather not have to update it just to get highlighting working. I had enough new things to learn with the migration.

I found Tokyo Night and after the initial few minutes of sadness from losing my trusted theme, I can honestly say that I’ve found a new love (I’m using the night variant). Tokyo Night even contains colors for kitty and tmux, which made it even better.

Settings and key mappings #

Here is how settings and key mappings differ between Vimscript and Lua. They aren’t that different, and they can be converted pretty quickly.

" Vimscript
" Settings
set termguicolors
set background=dark

" Global values
let mapleader="\<Space>"

" Simplify moving between panes
nnoremap <C-J> <C-W><C-J>
-- Lua
-- Settings
vim.opt.termguicolors = true
vim.opt.background = 'dark'

-- Global values
vim.g.mapleader = " "

-- Simplify moving between panes
-- Mode, my mapping, to mapping, options
vim.keymap.set("n", "<C-J>", "<C-W><C-J>", { noremap = true })

Conclusion #

I committed the first part of the conversion on January 3, 2023. Since then, I’ve been tweaking them almost every day. Incrementally making them better and better. If you’re curious, here’s the current state of the dotfiles.

Using tree-sitter and the built-in LSP is way faster than my old setup. Going to definitions is instantaneous. I would only get the squiggly lines on errors before, but now it’s typed out inline with the code.

Configuring is easier. Vimscript felt too foreign to me to ever want to learn, but with Lua, it’s not hard getting started. You can pick up the basics in a couple of minutes if you have some prior coding knowledge. After doing this conversion, I’ve found renewed happiness in tinkering with the dotfiles and my overall editor setup.


  • Loading next post...
  • Loading previous post...