david alfonso

Using a Lua-based Neovim config

When I migrated to Neovim some time ago, I took the easy path of just using my existing vim configuration (in VimL). It was fine and it worked. But if you want to experiment all the benefits of Neovim, you have to go Lua.

Choosing a base configuration

These are the Lua-based configurations that I researched:

I decided to use LunarVim's nvim-basic-ide as it seemed the most powerful, clean and updated.

Learning some Lua

Lua is well known for its simplicity and power. It's also designed to be embedded in applications which make it the perfect option to support user plugins and customizations.

Besides the official docs, just read the learnxinyminutes quick tutorial and have the Neovim references at hand:

Creating my config from the template

I decided to keep my Neovim config in a separate repo from my dotfiles, as I want to keep it in sync with upstream and have more freedom to branch and test new things.

GitHub uses the concept of templates to allow a "soft" clone where you don't inherit all the Git history. Instead, a new repo with the latest state of the template contents is created 1.

The new repo still points to the original stating:

generated from LunarVim/nvim-basic-ide

My config repo has a master branch that mirrors upstream and a new mine branch to keep my customizations.

$ git checkout -b mine

$ git push -u origin mine
To github.com:davidag/nvim-config.git
 * [new branch]      mine -> mine
Branch 'mine' set up to track remote branch 'mine' from 'origin'.

$ git branch -vv
  master ea52394 [origin/master] Initial commit
* mine   ea52394 [origin/mine] Initial commit

Referencing Neovim's config from my dotfiles repository

Since my dotfiles repo no longer contains my Neovim's config, there must be some mechanism in place to download it in the proper directory. This is a good use case for Git submodules.

# remove previous contents
~ $ git rm -rf .config/nvim

# add the submodule
~ $ git submodule add -f -b mine \
    https://github.com/davidag/nvim-config .config/nvim

We don't want absolute paths in .gitmodules:

[submodule "nvim"]
  path = .config/nvim
  url = https://github.com/davidag/nvim-config
  branch = mine
Continue setting up the local repo (unnecessary if you clone my dotfiles with --recurse-submodules):
~ $ git submodule init
Submodule 'nvim' (https://github.com/davidag/nvim-config) registered for path '.config/nvim'
When there are changes in my Neovim's config repo, I can update to these changes (since Git 1.8) with:
# This will update the commit referenced in `~/.config/nvim`
~ $ git submodule update --remote --merge

# Commit the new commit reference
~ $ git commit

The commit that removes my old vim config and adds a submodule with the new Lua-based Neovim config can be viewed here.