Keep two nvim setups easilly

Sérgio Araújo - Nov 25 '22 - - Dev Community

Update!

From now on consider only this first paragraph, once neovim developers implemented the environment variable called:

NVIM_APPNAME
Enter fullscreen mode Exit fullscreen mode

you can use it this way:

alias lv="export NVIM_APPNAME=lv; export MYVIMRC=~/.config/lv/init.lua;nvim"
Enter fullscreen mode Exit fullscreen mode

In my case I have created a special name called "lv". If I clone anyone nvim config file to the lv folder and run via terminal the lv command, this version of my config will be used.

I also have a more complex alias:

# https://gitlab.com/linuxdabbler/dotfiles/.config/nvim
# ln -sfvn ~/.dotfiles/vinone ~/.config
if [[ -d "$HOME/.config/vinone" ]]; then
    [[ ! `readlink "$HOME/.config/vinone"` =~ '.*dotfiles.vinone$' ]] && ln -sfvn ~/.dotfiles/vinone ~/.config
    alias vinone='(){(export NVIM_APPNAME=vinone;export MYVIMRC=~/.config/vinone/init.lua;nvim $@)}'
else
    alias vinone="nvim -u NONE -U NONE -N -i NONE -c 'set mouse=a| syntax on| set nu'"
fi
Enter fullscreen mode Exit fullscreen mode

Adding snippets to your custom neovim setup

In my custom setup I have a folder called "snippets". So inside the cmp.lua conf file I had to make this:

  local nvimAppname = vim.env.NVIM_APPNAME
  require("luasnip/loaders/from_snipmate").lazy_load({ paths = {"~/.config/".. nvimAppname .."/snippets"}})
Enter fullscreen mode Exit fullscreen mode

So if I start using this config file related to another NVIM_APPNAME it will not break the code.

Getting variables inside neovim

:lua print(vim.env.NVIM_APPNAME)
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .