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
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.
-
Thanks. It's not clear to me where the command will be run? In which pane will be the output?– cdupontNov 11, 2018 at 11:08
-
1This 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. Dec 27, 2018 at 3:16
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.
-
Thanks for the solution. However, I learned that it also prints the command to the terminal pane due. Dec 27, 2018 at 3:17