How to use Ctrl-semicolon for prefix in tmux? - tmux

I want to use Ctrl-semicolon for tmux's prefix. But my conf doesn't work.
unbind-key C-b
set-option -g prefix C-\;
I found a similar article. But it's not for the prefix.
tmux bind semicolon

Terminal can't register a Ctrl-; keystroke. It's just not a valid character. If you look at the control characters in the below ascii table, you'll see Ctrl-; is not on the list.
I'm on OS X and when I type Ctrl - ; in the (terminal and in a "desktop" program) I get a bell sound indicating the character is not recognized or something.
As for the "favorite" prefix key: from what I saw reading other people's .tmux.conf files, Ctrl-a is the most popular choice. This makes sense because:
Ctrl-a was the default for GNU Screen, tmux predecessor
it's much easier to type than the default Ctrl-b especially when you remap caps lock to ctrl.
The downside to using Ctrl-a is that you can't use the same key in bash or vim, but that's easily solved by having the following binding in .tmux.conf:
bind-key 'C-a' send-prefix
With that, pressing the Ctrl-a twice will send the same character to the underlying program (eg bash or vim).

As others said, you can't bind to Ctrl-; because it's not a valid character.
I like that prefix because it's really easy to press when CapsLock is remapped to Ctrl.
My workaround, for Linux, was to remap Ctrl-; to Ctrl-B at the xkb level.
Xkb is the Xorg subsystem which handles keyboard layouts.
I'm using the us layout, so I modified the /usr/share/X11/xkb/symbols/us at line 42:
key <AC10> { [ semicolon, colon ] };
to
// key <AC10> { [ semicolon, colon ] };
key <AC10> {
type="BABEL_CONTROL_LEVEL3",
symbols[Group1]= [ semicolon, colon, b ]
};
This tells Xkb to generate for AC10 (the 10-th button in the C row) semicolon at level 1 (no modifiers), colon at level 2 (shift modifier) and b at level 3 (Ctrl modifier).
Level 3 in Xkb is not activated by Ctrl generally, for this reason I created a new key type, which I called BABEL_CONTROL_LEVEL3. You need to put its definition in /usr/share/X11/xkb/types/pc:
type "BABEL_CONTROL_LEVEL3" {
modifiers = Shift+Control;
map[Shift] = Level2;
map[Control] = Level3;
level_name[Level1] = "Base";
level_name[Level2] = "Shift";
level_name[Level3] = "Control";
};
You'll need to restart X or reboot.
List of resources which helped me with this:
https://unix.stackexchange.com/questions/205226/xkb-make-ctrlbackspace-behave-as-delete
https://help.ubuntu.com/community/Custom%20keyboard%20layout%20definitions
https://wiki.archlinux.org/index.php/X_KeyBoard_extension

If you want to use control-semicolon, you can try AutoHotkey.
This is my tmux & autohotkey settings.
Tmux:
set-option -g prefix 'C-\'
AutoHotkey:
^;::
Send ^{\}
return

Related

OS X: How do I use the tmux prefix correctly?

I am following a tmux tutorial which states (Control + b) + % should open a new pane. When I try to do this from tmux though, the Control + b keypress just gets converted into a character which displays on the command line.
Various tmux tutorials seem to treat Control + b as a special keypress, but it always just appears as a character on my command line. How do I use the tmux prefix correctly?
That tutorial you linked to in your question has you overriding the default Control-b with Control-a
try (Control-a) + %
this is a popular override. I use it. My ~/.tmux.conf has:
set -g prefix C-a
unbind C-b
bind C-a send-prefix
this is nice when you also remap your caps lock key to be control, the caps lock key and the 'a' key are right next to each other

tmux changed keybinding (resizep) not working as expected

I use vim, and so I wanted to change a couple of tmux's default bindings. In particular I wanted to change the resizing commands so that e.g. ctrl-b ctrl-k resize the split up by one position. I entered the following into my .tmux.conf:
bind-key C-k resizep -U
and it works, except that it only allows me to resize by one unit at a time before I have to hit ctrl again. In other words, I can't hold down ctrl and press b followed by k a bunch of times (while still holding down ctrl), whereas I can hold down ctrl, press b, and then press the up arrow key a bunch of times.
Does anyone know exactly why this is, or how I might replicate my desired behavior?
You need to specify the -r parameter in your command:
bind-key -r C-k resizep -U
As explained in tmux man page:
bind-key [-cnr] [-t mode-table] key command [arguments]
(alias: bind)
Bind key key to command. By default (without -t) the primary
key bindings are modified (those normally activated with the
prefix key); in this case, if -n is specified, it is not neces‐
sary to use the prefix key, command is bound to key alone. The
-r flag indicates this key may repeat, see the repeat-time
option.

tmux send-keys syntax

On the tmux man page I found no reference to how it names keys.
For example, to send ctrl + r to tmux you would do:
tmux send-keys C-r
and to send the esc key you do
tmux send-keys Escape
Is there a list which maps keyboard keys to how tmux sendkeys expects you to name them? I have a feeling that I missed a memo that its using some-long-forgotten-program's syntax for convenience.
Note, this is nothing to do with key bindings.
The key names used by send-keys are the same ones that bind-key uses.
From the Key Bindings section of the tmux manpage:
When specifying keys, most represent themselves (for example ‘A’ to
‘Z’). Ctrl keys may be prefixed with ‘C-’ or ‘^’, and Alt (meta) with
‘M-’. In addition, the following special key names are accepted: Up,
Down, Left, Right, BSpace, BTab, DC (Delete), End, Enter, Escape, F1 to
F20, Home, IC (Insert), NPage/PageDown/PgDn, PPage/PageUp/PgUp, Space,
and Tab.
Although they are not listed in the man page, there are also special names for keypad-specific keys: KP0 through KP9, KP/, KP*, KP-, KP+, KP., and KPEnter.
Several of the more cryptic key names (BTab, IC, DC, NPage, PPage) probably come from the terminfo library.
Emacs shares the convention of using C- and M- prefixes to indicate modifiers (I would not be surprised if there were earlier uses of this convention).

Tmux special character support

I'm trying to remap the movement keys (between panes) in tmux to a Vim like style.
I don't like 'hjkl', and therefore I prefer to use the 'jkl;' keys. On my keyboard, the ';' character is 'ç' instead. I'm doing this:
bind j select-pane -L
bind k select-pane -D
bind l select-pane -U
bind ç select-pane -R
But it seems that tmux doesn't recognizes the 'ç' key. How can I solve this problem?
Currently, tmux does not really support binding keys whose core characters have multibyte representations. The internal key representation is mostly “8-bit plus modifiers”. Most terminals use UTF-8 these days, so your c-with-cedilla (U+00E7) is probably two bytes: C3 A7.
It should work if your terminal is using an 8-bit encoding. You would need to make sure your terminal is configured correctly, and also that your tmux client does not use UTF-8 (do not use the -u option, make sure LC_ALL, LC_CTYPE, and LANG all do not include UTF-8 or UTF8), do not enable the utf8 window option, and make sure your configuration file is saved with the same encoding that your terminal uses.
When parsing key strings from (e.g.) the bind-key argument, tmux treats any multibyte sequence (after stripping leading modifiers) as a named key (e.g. Up, PageUp, F1, KP0, etc.); see key_string_lookup_string in key-string.c. This is what causes the unknown key error message.
I have also previously written about this at Super User: tmux: trying to bind utf8 key.

give a hint when press prefix key in tmux

When I press the prefix-key Ctrl-b tmux doesn't give me a hint that it has been pressed.
Sometimes I can not remember whether I have already pressed it or not.
Can I set up a hint like highlight/change color or show some special symbol in the status bar to show me when I have pressed the prefix-key?
The development version of tmux has support for this, so the next release (1.8?) should also support it.
There have been two changes that can be combined to indicate in your status line whether a prefix key has been pressed:
You can include the extended “format” replacements in the values of the “status” options. These replacements were first available in tmux 1.6, but they were not previously usable in the status options.
The client_prefix format replacement was added.
You could add a (conditional) highlighted <Prefix> string before the default status-right like this:
set -g status-right ' #{?client_prefix,#[reverse]<Prefix>#[noreverse] ,}"#{=21:pane_title}" %H:%M %d-%b-%y'
There's also a Tmux plugin called tmux-prefix-highlight that does this.
It adds a new keyword, #{prefix_highlight} to use in the string that defines your tmux status bar, like so:
set -g status-right '#{prefix_highlight} | %a %Y-%m-%d %H:%M'
I created plugin for this. It indicates copy mode as well, is easily customizable and has good out-of-the-box experience.
https://github.com/dominikduda/tmux_mode_indicator
As readme says:
Plugin indicating normal/insert/prefix/copy modes.
It adds a new keyword, #{tmux_mode_indicator} to use in the string that defines your tmux status bar. Like this:
set -g status-right "#{tmux_mode_indicator}"

Resources