DEV Community

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

Posted on


Keep two nvim setups easilly

Because I love my neovim setup...

Every day we see astonishing new nvim configurations, we clone them, we test them, but most of the time we miss our old settings.

Create a second nvim setup:

We are going to change just three files:

1 - zshevn (or any environment settings of your shell)
2 - zsh-aliases
3 - mynvim (a script you can name as you want and put in your path).

Your zshenv:

When you want to use your alternative neovim settings just change the line EDITOR

export MYNVIM=~/.dotfiles/bin/mynvim

if [[ $(awk -F'/' '{print $NF}' <<<$EDITOR) == "mynvim" ]]; then
    export MYVIMRC="~/.nvim/config/nvim/init.lua"
    export MYVIMRC="~/.config/nvim/init.lua"
    export GIT_EDITOR="/bin/nvim"
Enter fullscreen mode Exit fullscreen mode

Your zsh-aliases:

if [[ $(awk -F'/' '{print $NF}' <<<$EDITOR) == "mynvim" ]]; then
    alias ne="mynvim ~/.nvim/config/nvim/init.lua"
    alias lvim="mynvim -c':e#<1'"
    alias vim=~/.dotfiles/bin/mynvim
    alias nvim=~/.dotfiles/bin/mynvim
    alias ne="nvim ~/.config/nvim/init.lua"
    alias lvim="vim -c':e#<1'"
    alias vim="/bin/nvim"
Enter fullscreen mode Exit fullscreen mode

The alias ne is an alias to edit your init.lua, the lvim opens your last edited file.

Your mynvim script:

#!/usr/bin/env bash
# source:
# Last Change: Wed, 16 Nov 2022 - 09:10:18
# vim:ft=sh:
# tags: [nvim, distro]

export MYCFG="${HOME}/.nvim"

[[ ! -d $MYCFG/config/nvim ]] && mkdir -p $MYCFG/config/nvim

export MYVIMRC="${MYCFG}/config/nvim/init.lua"
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 "$@"
Enter fullscreen mode Exit fullscreen mode

Using this settings I can clone anyone nvim config to "mynvim" folder and use without messing up with my default nvim settings. I can even create a second or third script using this idea. For now it works pretty well.

Top comments (4)

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.

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.

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:


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.

12 Rarely Used Javascript APIs You Need

Practical examples of some unique Javascript APIs that beautifully demonstrate a practical use-case.