DEV Community

Cover image for Keep two nvim setups easilly
Sérgio Araújo
Sérgio Araújo

Posted on Edited on

Keep two nvim setups easilly

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

Top comments (4)

Collapse
 
raguay profile image
Richard Guay

I have an easier way. I use LunarVim which creates it's own configuration with the command line name of 'lvim'. Then I have a normal Funnel powered config in the normal nvim config folder. Two different configs by accessing two different commandline names. The same can be done with others since you can give a new config location on the command line and alias it.

Collapse
 
voyeg3r profile image
Sérgio Araújo

Two problems: Lunarvim has a very tricky configuration and I want to use any nvim config, not just lunarvim.

Collapse
 
raguay profile image
Richard Guay • Edited

But, you can do it like they do by making an alias (script in their case) that specifies a different config directory. Then you just have a different alias for each config of neovim you have. The Lunarvim command is:

#!/bin/sh

export LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"/Users/raguay/.local/share/lunarvim"}"
export LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"/Users/raguay/.config/lvim"}"
export LUNARVIM_CACHE_DIR="${LUNARVIM_CACHE_DIR:-"/Users/raguay/.cache/lvim"}"

exec nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" "$@"
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
raguay profile image
Richard Guay • Edited

Then make use of the environment variables in the config. It's a little more work on the config, but it does get the end result you need.