Ever in a #Neovim :terminal
, and want to open a file without having to back out to normal mode, or have a nested Neovim instance? There’s several ways to do this, but here’s a simple one.
Add a shell function that tests $NVIM
, which is set to the server pipe when inside a Neovim instance. If Neovim is running, replace the nvim
command with an alias that passes the --server
and --remote
options.
Here’s a complete example for the Fish shell, but it should be easily adapted to others.
#!/usr/bin/env fish
function nvim --description "Open Neovim within the same instance, if one is running"
if test -n "$NVIM"
command nvim --server "$NVIM" --remote $argv
else
command nvim $argv
end
end