Maintaining a personal Neovim config is like a journey. Sometimes you wonder if you went down the wrong path (committed to plugins or settings you don't like anymore). Other times you just need to juggle between multiple destinations ( one config for work, another for personal projects).
Even though its common to keep this config in version control, its not always practical to use branches in Git to switch between different versions. For example, if your Neovim config is housed in a bigger, general “dotfiles” repo and switching branches would switch whole repo with other configs.
I found it easier to just maintain two config folders and point Neovim to use one or the other. You can tell Neovim to use an arbitrary config location via ENV vars but you have to use multiple of them and the paths are a bit hard to remember. So, id like to share with you this recipe of pointing Neovim to the right config:
#!/usr/bin/env bash if [[ ! -v NVIM_CONFIG_PATH ]]; then echo "NVIM_CONFIG_PATH is not set" >&2 exit 1 fi NVIM_DSC_PATH="/tmp/nvim_configs/${NVIM_CONFIG_PATH}/data_state_cache" NVIM_CONFIG_PATH_COPY="/tmp/nvim_configs/${NVIM_CONFIG_PATH}/config" mkdir -p $NVIM_DSC_PATH/{,data,state,cache} mkdir -p $NVIM_CONFIG_PATH_COPY rsync -a --delete $NVIM_CONFIG_PATH/ $NVIM_CONFIG_PATH_COPY/nvim/ exec env XDG_CONFIG_HOME=$NVIM_CONFIG_PATH_COPY \ XDG_DATA_HOME=$NVIM_DSC_PATH/data \ XDG_STATE_HOME=$NVIM_DSC_PATH/state \ XDG_CACHE_HOME=$NVIM_DSC_PATH/cache \ nvim $@
This also helps when using Neovim inside docker. I do a lot of my work development inside docker to keep all the development dependencies declared and easily rebuildable on a new machine.
Here is a recipe for launching a docker container with your Neovim config made accessible to it from the host
#!/usr/bin/env bash if [[ ! -v NVIM_CONFIG_PATH ]]; then echo "NVIM_CONFIG_PATH is not set" >&2 exit 1 fi NVIM_DSC_PATH="/tmp/nvim_data_state_cache" NVIM_CONFIG_PATH_LOCAL="/tmp/nvim_config" mkdir -p $NVIM_DSC_PATH/{data,state,cache} mkdir -p $NVIM_CONFIG_PATH_LOCAL rsync -a --delete $NVIM_CONFIG_PATH/ $NVIM_CONFIG_PATH_LOCAL/nvim/ docker-compose run -it \ -e NVIM_DSC_PATH=$NVIM_DSC_PATH \ -e XDG_CONFIG_HOME=$NVIM_CONFIG_PATH_LOCAL \ -e XDG_DATA_HOME=$NVIM_DSC_PATH/data \ -e XDG_STATE_HOME=$NVIM_DSC_PATH/state \ -e XDG_CACHE_HOME=$NVIM_DSC_PATH/cache \ -e LANG=en_US.UTF-8 \ -v $NVIM_DSC_PATH:$NVIM_DSC_PATH \ -v $NVIM_CONFIG_PATH_LOCAL:$NVIM_CONFIG_PATH_LOCAL \ app bash -c "/usr/local/bin/nvim $@"
Depending on your OS / shell / etc, some tweaks may be required so this is a general recipe that works for me right now (Linux+zsh). Hope this helps you easily switch between Neovim configs when you need to or to make your config available inside a docker container.
Cheers!