Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tmux bind semicolon

Tags:

bind

tmux

Is there some way I can bind ; (\059) to a command in tmux?

By default, it is bound to last-pane; however, I would like to rebind it to select-pane -R.

I have tried putting the following in my .tmux.conf, but none seem to work:

  1. "bind \059 select-pane -R" -> tmux reports "unkown key \059", but after ignoring the warning, ";" sometimes does work as intended.

  2. "bind ; select-pane -R" -> tmux reports "usage: bind-key ..."

  3. "bind ';' select-pane -R" -> tmux reports "usage: bind-key ..."

I'm using the first option now, but I'd like to do it correctly so I don't have a warning appear every time I start tmux.

like image 325
Samir Jindel Avatar asked Sep 30 '12 22:09

Samir Jindel


2 Answers

Semi-colon is also used as a command separator in tmux, so in order to bind it, you need to escape it:

bind-key \; select-pane -R
like image 58
Thor Avatar answered Sep 30 '22 13:09

Thor


tmux quoting is a bit quirky; it looks very much like Bourne shell-style quoting, but it has subtle differences.

The only thing that works to escape a trailing (or lone) semicolon is a backslash:

bind \; select-pane -R

The relevant part of the man page:

A literal semicolon may be included by escaping it with a backslash (for example, when specifying a command sequence to bind-key).

A trailing, unescaped semicolon acts as a separator between tmux commands.

tmux is showing you the bind-key usage (for your examples numbered 2 and 3) because when the semicolon is unescaped (even when it is quoted, unlike the shell), the line is parsed as two commands: bind and select-pane -R. The first of those commands is incomplete (bind-key requires at least two arguments: a key and a command).

Your \059 attempt (your example numbered 1) was likewise failing to adjust the bindings because the octal syntax is not supported when specifying keys. The default binding for Prefix ; is last-pane, which may end up moving a pane to the right (i.e. what select-pane -R does), but only if the next pane to the right happens to be the previously active pane.

like image 21
Chris Johnsen Avatar answered Sep 30 '22 12:09

Chris Johnsen