One of the reasons I switched to NeoVim instead of regular Vim was the built in terminal. In VSCode, I would typically have a terminal window open at the bottom of the editor, which I frequently used for git. Since I wanted to keep nvim as my editor of choice and use nvim's terminal for git, I faced a situation where I was opening nested instances of nvim, which is a recipe for a bad time. Luckily, I found some of the answer in the book Modern Vim. By installing installing neovim-remote (pip install neovim-remote) and using a little bit of .zshrc and .vimrc magic, I was able to open a new tab in nvim when running commands like git commit --amend to edit commit messages.
In my .vimrc file (actually I use a custom.vim file referenced by the fisadev .vim file) I put the following
" use remote neovim in new tab
if has('nvim') && executable('nvr')
let $VISUAL="nvr -cc tabedit --remote-wait + 'set bufhidden=wipe'"
endif
Which sets the $VISUAL editor environment variable to nvr (neovim-remote) if we're inside vim, and tells nvr to open a new tab
Unfortunately, this was being overwritten by setting $VISUAL in my .zshrc file run when a new terminal was opened in nvim. To solve this problem, I put the following in the .zshrc
if [ ! -v VISUAL ]; then
export VISUAL="nvim"
fi
Also, to ensure I never opened nested instances of nvim, I put the following in as well
if [ -n "$NVIM_LISTEN_ADDRESS" ]; then
if [ -x "$(command -v nvr)" ]; then
alias nvim=nvr
else
alias nvim='echo "No nesting!"'
fi
fi
This made everything work correctly for amending commits in the NeoVim terminal, but I found another problem: my session autosave code in my .vimrc file created a .session.vim file in a directory when it quit, and loaded the file when started in the directory. Running git commit --amend outside of nvim now caused that session to open instead of the commit message! To solve this, I changed the previous export of the $VISUAL environment variable a bit
if [ ! -v VISUAL ]; then
export VISUAL="NOSESSION=true nvim"
fi
In my .vimrc autosave/autoload functions, I check for that environment variable and return if it's true to avoid using sessions for editor instances opened by programs using $VISUAL
if $NOSESSION == "true"
return
endif
So now I can easily do my entire git workflow both inside of nvim and outside of it.