I'm usually running one tmux session for all the work I do, with per-project tmux windows (tabs). Each tmux window has one big split running vim and one or more splits with shells/processes related to the project. E.g. for a django project, one shell always runs manage.py runserver, showing me logs and errors, and another is for moving files around, creating folders, copying stuff etc.

I often find myself typing "vim somefile.py" in that work shell split, spawning another (very small) instance of vim. What I would like to achieve is having that vim command open a buffer with the specified file in the already opened vim instance. I know it's possible with vim's remote feature, but I wonder if there's a way to automate this, i.e. wrap the vim command to autodetect if there's an instance running in the same tmux window and then send the remote command, or spawn the vim instance if none is running.

I would not want is to have the vim command send a remote command to a vim instance in another tmux window, as that would be another project. Is there anything available already (vim or tmux plugin, wrapper script, ...)?

1 Answer 1


You could make a vim function in your zsh or bash startupfiles .zshrc or .bashrc

Something like

if pgrep vim; then
    vim --servername --remote $*
    vim --servername tmux $*

But actually, I found out Vim automatically executes the server if it doesn't exist:

$ vim --servername --remote TEST
E247: no registered server named "TEST": Send failed. Trying to execute locally

Press ENTER or type command to continue

If you can't live with that delay/ENTER prompt then try to customize script function #1 to your liking

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .