In ~/.tmux.conf
, with
bind-key v split-window "vim"
I can launch vim in a split window.
how I can use two keys in a tmux bind-key
?
Example:
bind-key vG split-window "vim +$"
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityYou cannot. tmux
only allows single-key bindings (either alone, using bind-key -n
, or following the prefix key).
However, you might try binding "v" to an invocation of command-prompt
:
bind-key v command-prompt "tmux-vim.bash %%"
where tmux-vim.bash
looks something like
if [ $1 = "G" ]; then
tmux split-window "vim +$"
fi
Then, after typing v to get to the command prompt, you would just type "G" and press Enter. "G" would be passed as the argument to tmux-vim.bash
, and that script would take care of executing the tmux
command you (originally) wanted to associate with "vG".
bind -c
+ command -c
Jul 10, 2012 at 0:18
There is only one right solution for it:
# you can use "vim +$" as well, but I don't think that +$ prefix have any sense without the file path argument...
bind -T multiKeyBindings G split-window "vim"
bind v switch-client -T multiKeyBindings
If you want the possibility to pass custom arguments, you should use this one instead:
bind -T multiKeyBindings G command-prompt 'split-window "vim %%"'
bind v switch-client -T multiKeyBindings
More examples:
# Toggle maximizing of current pane by typing PREFIX mm
bind -T multiKeyBindings m resize-pane -Z
bind m switch-client -T multiKeyBindings
# or without PREFIX
bind -T multiKeyBindings m resize-pane -Z
bind -n m switch-client -T multiKeyBindings
# rename current window by typing PREFIX mr
bind -T multiKeyBindings r command-prompt 'rename-window %%'
bind -n m switch-client -T multiKeyBindings
You should use a unique key tablet's name for each multi keybinding. Example:
bind -T multiKeyBinding1 G split-window "vim"
bind v switch-client -T multiKeyBinding1
bind -T multiKeyBinding2 m resize-pane -Z
bind -n m switch-client -T multiKeyBinding2
MultiKeyBinding_v
, MultiKeyBinding_m
, etc...
As @chepner said, you cannot do this directly. What you can do is bind v
to create a binding for G
that does what you want and then unbinds itself.
bind-key v bind-key -n G split-window "vim +$" \\; unbind -n G
There are a couple of important things to note with this approach:
G
); If you want to have something bound to G
and something else bound to vG
your unbinding step needs to restore the original binding.tmux
will segfault if your .tmux.conf
includes a bind-key
statement that is too long. If this becomes a problem, you can work around it by putting your context switching in bash scripts and then bind a key to run those scripts.For a more involved example, see this gist.
After 2015, yes you can do this.
They add a new argument -T key-table
to switch-client
command to support this feature.
Here's the commit: https://github.com/tmux/tmux/commit/bded7437064c76dd6cf4e76e558d826859adcc79
Maybe they released this feature at version 2.1, but I did not saw any release notes mentioned this.
Here's the way to archive this goal:
task: do something like: bind-key vG split-window "vim +$" code:
bind-key -T prefix v switch-client -T prefix_v
bind-key -T prefix_v G split-window "vim +$"
Beyond the command-prompt
approach suggested on the other answers, you can have a second set of mappings using a different prefix:
prefix key
Set the key accepted as a prefix key.
prefix2 key
Set a secondary key accepted as a prefix key.
Thus you could do the following:
set -g prefix C-v
bind-key G split-window "vim +$"
to map to c-v g
instead of c-b vG
. The downside is that it will shadow any default mapping, as it will also be accessible through c-b g
.