tmux-vim is a bash script which works in conjunction with tmux to create a persistent vim pane within a tmux window.
Use tmux-vim just like you'd use vim.
tmux-vim [file] [files...]
The first time you run it, a new pane will be created besides your current
tmux window according to
TMUX_VIM_SPLIT, running an instance of vim.
Further calls to tmux-vim will open the files in new buffers in the same vim session.
If you close that vim session, the pane will be destroyed. The next call to tmux-vim will create a new one.
Copy tmux-vim to somewhere in your path.
You need tmux version 1.6 or later.
By default tmux-vim will split the shell pane according to the size defined
TMUX_VIM_SHELL_HEIGHT, let the vim pane occupy
the rest space.
In a 'HORIZIONTAL' split, if either
TMUX_VIM_VIM_WINDOW_COUNT is set, the tmux-vim will caculate the width of
the vim pane to ensure it can hold as much
possible and leave shell pane at least
TMUX_VIM_SHELL_WIDTH width. But if
current screen can only hold one window size of vim, then
will be ignored.
This behaviour can be adjusted with the following environment variables.
You can set these variables in ~/.tmux-vim.conf.
Value: [ 'HORIZONTAL' | 'VERTICAL' ]
Optional, default is 'HORIZONTAL'.
Define how tmux-vim split panes.
Command-line arguments to pass through to vim.
Optional, default is 80.
TMUX_VIM_SPLIT is 'HORIZONTAL', then this variable defines the minimum
width of the vim pane.
Optional, default is the same as
Width of a single vim window in columns.
Specify a fixed number of vim windows with this.
Value: [ 'TRUE' | 'FALSE' ]
Optional, default is 'FALSE'.
If this variable is set to 'TRUE', then the vim will be splitted according to
the caculation of
Optional, default is 132.
TMUX_VIM_SPLIT is 'HORIZONTAL', then this variable defines the width of the
On narrow displays, one vim pane will always be created, even if this means
we leave less that
TMUX_VIM_SHELL_WIDTH columns for the shell.
Optional, default is 15.
TMUX_VIM_SPLIT is 'VERTICAL', then this variable defines the height of the
How's it work?
tmux makes it all possible.
tmux split-window is used to create the vim pane, and the pane id is
saved in the tmux environment. This happens on demand - panes are created only
The vim instance is controlled by injecting keystrokes with
tmux send-keys. To load a file, tmux-vim sends
:edit filename<cr> to the
tmux select-pane transfers control over to the vim pane.
By default, vim won't abandon an unsaved file to open another one, instead the user is prompted to save, abandon or cancel. This can throw out the keystroke injection when trying to open multiple files.
To avoid this problem, files are loaded with calls to
:badd rather than
:edit. After the last buffer is added,
:buffer is used to switch to it. This
delays the user prompt until the very end, when the user has regained control.
This appears to work, but there may still be issues lurking.
When the vim pane is created, the current directory is saved in the tmux environment. The directory is used when computing relative paths. If the user manually changes the vim working directory, the relative paths will break.