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.
Related
I'm starting to use zsh on macOS Sierra. I would like to have the following key mappings:
Enter => accept-line
Shift-Enter => accept-and-hold
However, I can't seem to differentiate between the two. I'm only able to get Enter, and Esc-Enter, but not Shift-Enter:
bindkey "^M" accept-line # Enter
bindkey "^[^M" accept-and-hold # Esc-Enter
bindkey "????" accept-and-hold # Shift-Enter
Is it possible to detect and handle Shift-Enter?
zsh (as well as other shells) do not act on key bindings but rather on key sequences received from the terminal. Converting key presses and combinations into key sequences is the responsibility of the terminal. You can retrieve the key sequence for a key combination by pressing Ctr+v followed by the key combination, e.g. Shift+Enter.
By default Enter and Shift+Enter (as well as Ctrl+v and Ctrl+Shift+m) all generate the identical key sequence ^M (at least in most common terminal emulators).
Fortunately, some terminal emulators allow to configure the key sequences sent. For example iTerm2 allows you to set customized key bindings that send escape sequences (in Profile > Keys), you should be able to define a sequence for Shift+Enter there, e.g. [[SE and can then make the appropriate settings in zsh: bindkey '^[[[SE' 'accept-and-hold'. (Unfortunately I do not have access to a Mac at the moment, so I could not test this).
This might answer your problem (can't put it into comment, don't have 50 rep). You might try # showkey --scancodes which gives you key codes and take a look into the manual-pages e.g. man zshzle and search for "code". I have tried to map the shift key without success. Might be it's not possible. Also have a look into bindkey -l wich gives you the keymaps and bindkey -M emacs for emacs keymap
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.
I'm trying to make Alt-h switch to the left pane in Tmux. This does not work:
bind -n M-h select-pane -L
Pressing Alt-h in cat generates the following output in my terminal:
$ cat
^[h
That is, it looks like Alt generates ^[ in my terminal. So, in my Tmux configuration, I have also tried this binding:
bind -n ^[h select-pane -L
I have made "^[" both a literal two character string (i.e., "^" + "[") as well as the special "^[" character you can access in Vim. Neither work.
How to solve this problem?
EDIT: I'm primarily using xfce4-terminal as my terminal emulator, but I've tried using gnome-terminal as well as xterm, and the problem persists.
Actually the secret is how you enter ^[ ;-)
I assume you want to edit your .vimrc
vim ~/.vimrc
navigate to the correct position
press i
press ctrl-v
press ctrl-[ (on a german keyboard I have to press ctrl-altgr-8 because altgr-8 is [)
After that you should have the escape sequence generated required to write the binding.
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
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).