4

I would like to try out some fancy plugins, debug my own configuration and plugins, try out new Neovim versions. But I do want to keep my daily used Neovim stable (with fixed set of settings and plugins). I do not want to test them out in my normal home dir. I wonder if there is a way to provide me this convenience like python venv provided to python users.

I would like to be able to specify the Neovim environment like source <nvim env 1>/bin/active or similar. Then the nvim won't look for my ~/.config/nvim or install plugins to ~/.local/*/nvim or similar paths. Instead everything should go into <nvim env 1>.

I would like to be able use several different environments simultaneously. This means any solution, that requires to mess around in my ~/.config or ~/.local to setup symlinks as workaround, actually won't work. For example:

  • cheovim
  • nvChad
  • GNU stow

update

after digging around in the document, I think the best way to achieve this in neovim is to play with some variables:

  • a shell environment variable: VIMRUNTIME, this may not be necessary, if nvim is installed with standard dir structure under parent dir.
  • a shell environment variable: VIMINIT or MYVIMRC to change the first configure file it is going to load
  • another shell environment variable: XDG_CONFIG_DIRS, system wide configs.
  • in the virtual nvim rc, we need to set runtimepath to get rid of the ~/ parts.

I will keep experimenting this. I actually hope other neovim developers had already done this. Otherwise, developing neovim is still very messy for the rest of us who do not want to fire up a vm.

4 Answers 4

2

Specifically, Neovim supports :h xdg set of directories. That is, you need to do something like

MYCFG=~/foo

export XDG_CONFIG_HOME=$MYCFG/config
export XDG_DATA_HOME=$MYCFG/data
export XDG_CACHE_HOME=$MYCFG/data
export XDG_STATE_HOME=$MYCFG/data
# this is for temporary files, so better to leave as is
#export XDG_RUNTIME_DIR=...

nvim

Then config must go under ~/foo/config/nvim, while ~/foo/data/nvim will hold shada, log and all such.

0

For regular Vim, muru's suggestion of running with a different $HOME works great, and I imagine it would also work for Neovim:

Put your desired configuration files in /path/to/temporary/config, and run:

$HOME=/path/to/temporary/config nvim
6
  • This will be a nice solution if I do not need common external dependencies that I installed to ~/.local like fzf, fd, etc.
    – Wang
    Commented Sep 5, 2022 at 10:30
  • @Wang What causes your dependencies to fail with this solution? ~ should point to the same altered $HOME when running the above.
    – Rich
    Commented Sep 5, 2022 at 10:30
  • the $PATH will expand the ~/.local to the new home dir, which does not contain those external commands. But I my be able to work around by insert the original realpath(~/.local/bin) between the ${HOME}/.local/bin and /usr/local/sbin. It is tricky
    – Wang
    Commented Sep 5, 2022 at 10:34
  • Could you symlink the external commands into the temporary location to make it a complete installation?
    – Rich
    Commented Sep 5, 2022 at 10:38
  • 1
    also any external program need to read files in ~ will fail in this way. Not good, too broken. I wonder if there is a VIMPATH like PYTHONPATH. basically I have VIMPATH=$NEWVIMDIR, PATH=$NEWVIMDIR:$PATH Then anything existing in NEWVIM will be used first, anything that does not exist will expose the system one. The nvim will still load and only load plugins from NEWVIM. I guess it won't be possible, beause the paths VIM look for plugins are hard coded.
    – Wang
    Commented Sep 5, 2022 at 10:45
0

You can use Docker to try out new environments. It is, in my opinion, the easiest solution with no need to dig yourself into environment variables, etc.

For example, you can try AstroNVim without touching any configuration by running their official Docker instance with the following command:

docker run -w /root -it --rm alpine:edge sh -uelic '
  apk add git nodejs npm lazygit ncdu htop python3 neovim ripgrep alpine-sdk --update
  git clone https://github.com/AstroNvim/AstroNvim ~/.config/nvim
  # Uncomment the line below and replace the link with your user config repo to load a user config
  # git clone https://github.com/username/AstroNvim_user ~/.config/nvim/lua/user
  nvim --headless -c "autocmd User PackerComplete quitall" -c "PackerSync"
  nvim
'

1 Code snippet from Docker Installation section at: https://astronvim.github.io/

Another example would be SpaceVim's Docker instance that you can try out with the following:

docker pull spacevim/spacevim
docker run -it --rm spacevim/spacevim nvim

You can also load local configurations:

docker run -it -v ~/.SpaceVim.d:/home/spacevim/.SpaceVim.d --rm spacevim/spacevim nvim

2 Code snippets from Run in Docker section at: https://spacevim.org/quick-start-guide/

You can create as many custom configurations as you want, combine them, put them in a Docker container, upload them on Docker Hub, and try them out on any device, with one or two commands at most.

These may be some helpful resources to get started:

0

Neovim now has the environment variable NVIM_APPNAME. In my case I have this:

alias lv="export NVIM_APPNAME=lv; export MYVIMRC=~/.config/lv/init.lua

Now every time I star the "lv" it will run neovim with its settings on ~/.config/lv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.