Edit a file using a single instance of Vim/gVim/Neovim
Name | Link |
---|---|
Project Home: | https://github.com/davidosomething/vopen |
This uses Vim's server capability to use a single instance of Vim. It also intelligently determines when to use that capability:
- If on Linux with an X Server, will use
gvim
- If on Mac, it will use
gvim
(which is the same as MacVim.app if you use that) - If in an SSH session or linux with no X11 it will use terminal Vim with no server.
It takes of Vim's normal args if you provide any extra ones.
- Add the
vopen
file somewhere in your path, e.g./usr/local/bin/
- Optionally add the
vopen-nofork
file somewhere in your global path (make sure the root user/sudo has this in its path), e.g./usr/local/bin/
. This is for$EDITOR
/$SUDO_EDITOR
, and is compatible withgit commit
,visudo
,vipw
, etc.
vopen (args) (filenames/directories)
Typically I alias "vopen" to "e".
alias e="vopen"
Use the nofork version vopen-nofork
for $EDITOR
and $VISUAL
if you plan
on modifying your env (.bashrc
/.zshrc
/etc.).
export EDITOR="vopen-nofork"
export SUDO_EDITOR="vopen-nofork"
export VISUAL="vopen-nofork"
You can start Vim with a default command using the VOPEN_DEFAULT_COMMAND
global variable in your system. E.g. to start vimfiler:
export VOPEN_DEFAULT_COMMAND="+VimFilerCurrentDir"
The format is any Vim-compatible args (the plus sign means run this command).
For neovim-remote I recommend the following:
export VOPEN_SERVERNAME="$NVIM_LISTEN_ADDRESS"
export VOPEN_DEFAULT_COMMAND="--remote-silent +enew"
export VOPEN_REUSE_COMMAND="--remote-silent"
export VOPEN_EDITOR="nvr"
export VOPEN_VISUAL="nvr"
If there's an existing editor server as detected by $VOPEN_EDITOR --serverlist
,
and you run vopen
without any arguments, it will try to use the
VOPEN_REUSE_COMMAND
by default.
For Vim with +clientserver
, the default reuse command is
--remote-send \":call foreground()<CR>\"
, which will bring the instance to
the foreground. See :h foreground()
in Vim for details.
For Neovim with neovim-remote I recommend the following:
export VOPEN_REUSE_COMMAND="--remote-silent +sleep"
which does a silent no-op and will suppress neovim-remote messages.
vopen
supports environment variables for specifying what command to run for
the editor and gui editors.
VOPEN_EDITOR
defaults tovim
. I.e., for neovim-remote set tonvr
.VOPEN_VISUAL
defaults togvim
. I.e., for neovim-remote set tonvr
.VOPEN_USE_GUI
defaults to true if you have a gui-capable display (x11/osx).VOPEN_USE_SERVER
defaults to true, use to disable server altogetherVOPEN_SERVERNAME
defaults toVOPEN
to use a single instance calledVOPEN
. I.e., for neovim-remote set to$NVIM_LISTEN_ADDRESS
.
Here is an example using Neovim as the terminal editor and coolwanglu/neovim-e
as the gui editor:
export VOPEN_EDITOR="nvim"
export VOPEN_VISUAL="/Applications/Electron.app/Contents/MacOS/Electron ~/src/neovim-e"
export VOPEN_USE_GUI=false
export VOPEN_USE_SERVER=false
Here is an example using neovim-remote:
export NVIM_LISTEN_ADDRESS=/tmp/nvimsocket
export VOPEN_SERVERNAME="$NVIM_LISTEN_ADDRESS"
export VOPEN_EDITOR="nvr"
export VOPEN_VISUAL="nvr"
export VOPEN_DEFAULT_COMMAND="+enew"
export VOPEN_REUSE_COMMAND="--remote-silent +sleep"
If you're using a version of Vim (e.g. neovim-e) that does not support servers
but you still want to use vopen
for some reason, you can disable servers:
export VOPEN_USE_SERVER=false
There is also a commandline flag:
vopen --noserver myfile.txt
Run vopen
with the environment variable VOPEN_DEBUG
set to see what it will
execute. I.e.
VOPEN_DEBUG=1 vopen
- FIXED - neovim-remote 1.6.0 fixes for silent opening; cut 1.3.0
- CHANGED - check for
--version
flag and pass through directly to editor (directly to nvim if using nvr)
- ADDED - learned VOPEN_REUSE_COMMAND env option
- ADDED - learned VOPEN_DEBUG env option
- ADDED - neovim-remote support, cut 1.0.2
- ADDED - learned VOPEN_SERVERNAME env option
- ADDED - VOPEN_USE_GUI if you want to never use the gui
- FIXED - better logic to determine what editor mode to use
- FIXED - quoting
- CHANGED - remove bash error modes (v0.1.0)
- CHANGED - no --nofork mode for nvim either (v0.0.10)
- CHANGED - detect nvim and default to serverless since there is no server mode (v0.0.9)
- CHANGED - default servername is now suffixed with -VOPEN to distinguish from
--nofork
runs
- ADDED -
--noserver
flag, cut v0.0.7
- FIXED - quote file paths, files w/escaped spaces work now
- ADDED - env vars for VOPEN_VISUAL, VOPEN_EDITOR, VOPEN_USE_SERVER
- FIXED - use
$OSTYPE
instead of my shell var
- ADDED -
--servername
flag will properly override servername.
- FIXED - Server is not used when
--nofork
arg is present.
- published