12

I use tmux to develop, with two panes: one to edit the code, and one to compile it. I need to switch pane very often to launch the compile command (say "mvn install").
How can I bind a key (say "Ctrl+B C") to launch that specific command in the other pane (or without any pane at all)?

2 Answers 2

17

The right answer to this question is: use bind-key, e.g.:

tmux bind-key "$KEY" run-shell "/path/to/script.sh"

where KEY=C in your case.

2
  • Thanks. It's not clear to me where the command will be run? In which pane will be the output?
    – cdupont
    Nov 11, 2018 at 11:08
  • 1
    This should be the accepted answer. meuh's answer works but it simulates real human interaction, thus results in printing the command into the terminal pane.
    – elquimista
    Dec 27, 2018 at 3:16
11

C-b c already has a standard binding which it might be wise to leave unchanged. Choosing another character, eg C-b C you can setup a binding in your ~/.tmux.conf file as follows:

bind C send-keys -t.- 'mvn install' Enter

The -t.- means "the other pane". Enter stands for the key of that name, i.e. the newline at the end of the command.

1
  • Thanks for the solution. However, I learned that it also prints the command to the terminal pane due.
    – elquimista
    Dec 27, 2018 at 3:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .