tmux bind-key with two keys

You 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".


Answer

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

The notable thing

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

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:

  1. This will conflict with existing top-level bindings (in this case 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.
  2. 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 +$"