sponsor Vim development Vim logo Vim Book Ad

vimtux : Send commands from Vim to Tmux.

 script karma  Rating 0/0, Downloaded by 235    Comments, bugs, improvements  Vim wiki

created by
Christian Brauner
script type
Find the current script on Github: https://github.com/lord-garbage/vimtux

This is a simple Vim script to send text, commands and keys from a Vim buffer to a running tmux session. Its main objective is to stay as simple as possible following the famous KISS principle. This means it does not rely on the presence of any external files, programming languages whatsoever and it will stay that way. Forever. Period. It does exactly what it was designed for no more no less: Send text, commands and keys to any Tmux session via Vim. You will find the details below.

Note: If you use version of tmux ealier than 1.3, you should use the stable branch. The version available in that branch isn't aware of panes so it will paste to pane 0 of the window.

(1) vimtux provides the ability to send multiple keys to a tmux target at once.

(2) The tmux target is set on buffer basis. This means that every tab in Vim can have its own tmux target. (E.g. you could have a tab in which you edit a Python script and send text and keys to a Python repl and another tab in which you edit an R script and send text and keys to an R repl.)

(3) vimtux allows you to refer to panes and windows either via their dynamic identifier which is a simple number. Or via their unique identifier. For panes their unique identifier is a number prefixed with % and for windows a number prefixed with @.

a) Demonstrative Reference/Dynamic Reference:

Panes: If you choose to refer to a pane via its dynamic identifier the target of any given send function in this script will change when you insert a new pane before the pane you used.

Windows (slightly more complex to explain): Assume you have set set-window-option -g automatic-rename on in your ~/.tmux.conf. This is quite useful when you want to have an easy way of seeing what program is currently running in any given tmux window. But it is not very useful when you switch programs in a tmux window a lot but still want to be able to send commands and keys from the same window or pane to these different programs. Because refering to the window via its name given to it by the program currently running will break the connection between the window running the program and the window you are sending commands and keys from once that program is exited.

b) Proper Name/Static Reference: If you choose to refer to a pane via its unique identifier the target of any given send function in this script will stay fixed.

b) Proper Name/Static Reference: If you choose to refer to a window via its unique identifier the target of any given send function in this script will stay fixed while allowing that the program currently running in that window is setting the name for that session.

Tip: You can find out the unique identifier of a pane by either passing tmux list-panes -t x where x is the name of the session. Or (the easier way) you let the unique identifier of every pane be shown in your tmux status bar with the option #D; e.g.: set -g status-left '#D'. (All possible options about what to display in the statusbar can be found via man tmux or some internet searching.)

I suggest using something like this in your .tmux.conf:

# Status bar.

set -g status-interval 2

set -g status-right '[#D|#P|#T] '

set -g status-left '[#{session_id}|#S]'

set-option -g status-justify centre

# Disable showing the default window list component and trim it to a more specific format.

set-window-option -g window-status-current-format '[#F|#{window_id}|#I|#W|#{window_panes}]'

set-window-option -g window-status-format '[#F|#{window_id}|#I|#W|#{window_panes}]'

which gives you: #{session_id} := unique session ID, #S := session title, #F := window flags (Info about which windows is active etc.), #{window_id} := unique window ID, #I := window index, #W := window title, #{window_panes} := number of active panes in current window, #D := unique pane number, #P := dynamic pane number, #T := pane title, The characters [, ] and | are just used to secure visibility and do not have any further meaning.

A last hint: If you fancy it you can rename panes. Just issue printf '\033]2;%s\033\' 'hello' in any pane and observe how #T will change.

(For fun: Consider including #D and #P in your statusbar for a moment in order to see how tmux changes the dynamic window number for every pane that comes after the one you just opened and how #D stays fixed.)

(4) Keybindings are not set automatically for you. Instead, you can map whatever you'd like to one of the plugin-specific bindings in your .vimrc file.
install details
Put in your plugin folder.

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vimtux.vim 1.5 2014-09-04 7.0 Christian Brauner renaming, cleaning code
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo