4

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 +$"
5

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

4

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.

0

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.