How to use Ctrl-semicolon for prefix in tmux?

末鹿安然 提交于 2019-12-09 16:55:46

问题


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

BTW, what's your favorite prefix key? :D Do you have a recommend key?


回答1:


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).




回答2:


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



回答3:


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


来源:https://stackoverflow.com/questions/30680362/how-to-use-ctrl-semicolon-for-prefix-in-tmux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!