Ray*_*ews 24 zsh terminal keyboard key-mapping
我们是否有一个键绑定表来翻译所有指代按键的方式?我正在使用zsh,但我认为如果有这样的表,它将适用于任何外壳。
我问的原因是我想分配一些键绑定,但我不知道如何引用它们(除非我要窃取一个已经定义的)。
例如,在“zbindkey”中,我们有这样的事情:
[[ "$terminfo[kend]" == " O"* ]] && \
bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
Run Code Online (Sandbox Code Playgroud)
...我可以猜到“kend”意味着这是指End钥匙。
交叉检查bindkey我看到这些行:
"^E" end-of-line
"^[OF" end-of-line
"^[[F" end-of-line
Run Code Online (Sandbox Code Playgroud)
...所以我相信其中一行是指End密钥。哪一个?
我们在“bindkey”文件中也有这个:
bindkey "\e[A" history-beginning-search-backward
Run Code Online (Sandbox Code Playgroud)
现在,我碰巧知道那是Up Arrow关键,但如果我不知道,我怎么知道呢?
$ bindkey (at CLI)
Run Code Online (Sandbox Code Playgroud)
... 为同一个键提供了不同的语言:
"^[[A" history-beginning-search-backward
Run Code Online (Sandbox Code Playgroud)
...但至少现在我知道 ^[[A在 bindkey-at-CLI 中说话与\e[A在 bindkey-in-zbindkey 中说话是一样的。这很容易。在过去的DOS下,Up Arrow 是0;72-你会发现每一个法律按键的扫描码,有仅仅是一种语言。
有桌子吗?或者能够选择击键并知道如何terminfo[]在“bindkey-in-zbindkey”中……在“bindkey-at-CLI”和/或任何其他语言中引用它的其他方式碰巧是?
同样,在 DOS 中有scancode程序——键入一个键,你就得到了扫描码。这太容易了。
从答案中我猜想没有办法打印出所有可能绑定的表格?无论如何'bindkey'几乎可以满足我的要求:
pts/2 HP-y5-10-Debian1 root /aWorking/Docs $ bindkey -L
bindkey "^@" set-mark-command
bindkey "^A" beginning-of-line
bindkey "^B" backward-char
bindkey "^D" delete-char-or-list
bindkey "^E" end-of-line
...
Run Code Online (Sandbox Code Playgroud)
至少我可以看到所有现有的绑定,即使不是所有可能的绑定。现在,如果有某种方法可以将关键字形转换为“常规”术语:
bindkey "Home" beginning-of-line
Run Code Online (Sandbox Code Playgroud)
……那我就高兴了。
Gil*_*il' 18
终端应用程序和终端仿真器(或硬件终端)之间的接口传输字节,而不是密钥。诸如光标移动键之类的功能键被转换为转义序列(以转义字符 ESC \eaka \033aka 0x1b aka ^[开头)。功能键或字符键与修饰符的组合也是如此,尽管并非所有终端都为所有不同的修饰符组合发送不同的序列。一些键被编码为控制字符(例如Tab? Ctrl-I \t== \011)。
如您所见,描述控制字符的方法有很多种。有些有一个名称,对应于它们的传统功能(例如制表符、换行符);这些往往有一个反斜杠+字母组合,你可以在里面使用$'…'的参数或对echo或print(和在sed正则表达式,并在AWK,C和其他语言(注意字符串文字,不同的工具可能有一个稍微不同的一组转义序列))。您也可以\033在这些上下文中使用反斜杠+八进制(例如)。
对于每个键发送的转义序列终端有一些变化。幸运的是,几乎没有重叠:很少有字符序列表示不同终端上的不同键。主要问题是字符 127 == \1770x7f,现在最常见,Backspace但有时也有Delete。
^[OF和^[[F(即\eOF和\e[F)是发送的两个常见的转义序列End。^E(ie \005) 是 Emacs 的键绑定 ( Ctrl+ E) end-of-line。
要查看终端模拟器针对特定键或组合键发送的内容,请按Ctrl+ V,然后按相关键。这会逐字插入转义序列的第一个字符。转义序列通常由一个转义字符后跟可打印字符组成,因此转义序列的其余部分也按字面插入。
Terminfo 数据库包含一些键的转义序列。您可以在系统的terminfo(5)手册页中找到 Terminfo 功能列表。在zsh中,可以通过terminfo关联数组列出数据库中的值。当打印出包含转义序列的值时要小心,这些转义序列在显示时也由终端解释,所以以引用的形式打印它们。
% print -lr ${(q)terminfo[kend]}
$'\033'OF
Run Code Online (Sandbox Code Playgroud)
请参阅键盘输入和文本输出如何工作?更完整地了解按下按键时发生的情况。没有必要了解 zsh 中的键绑定。
Ray*_*ews 13
BEGINNER'S GUIDE TO ZSH KEYBOARD ASSIGNMENTS, AKA 'KEYBOARD BINDINGS'.
Run Code Online (Sandbox Code Playgroud)
(欢迎评论,改进,严厉谴责:东连点加州的rayandrews)
连接到在 Debian Linux 下在 xfce4 下运行“zsh”的 PC 的“101”PC 键盘上的“可用”键组合(我不知道谁是“负责人”)。除了显示的最简单的头像外,所有在“灰色”键内产生重复代码的组合都已被删除。请注意,某些灰色键/组合具有 '^letter' 重复项,例如 'Enter' == '^M',这些尚未删除。由于系统使用了其他活动组合,因此即使从控制台使用,也“不可用”,例如。“Alt+Function”键切换终端。也许“元”键会做更多,但这是 101 KB。有趣的是,在 DOS 中有更多可用的组合,例如 Ctrl+Function —— 都在 DOS 中可用,但在 Linux 中没有一个可用,所以看起来。三重键组合(例如“Ctrl+Alt+Up”)都没有在灰色键中产生任何唯一代码,但它们确实在白键中产生代码。有趣的异常: '^[[22' '^[[27' '^[[30' 'missing',你很想知道为什么这些数字被跳过了。(也就是说,您可能希望 'F11' 是 '^[[22' 而不是 '^[[23'。)
显示的密钥代码与在 CLI 中由“showkeys -a”或“bindkey”输出的一样。但是,出于某种原因,如果您在脚本中使用 'bindkey'(如在 '.zshrc' 中)' ^[ ' 必须替换为 ' \e ',因此在 CLI 中:
bindkey -s '^[[[A' '我的命令 \Cm'
... 将“F1”绑定到“my-command”并执行它(“\Cm”模拟“Enter”键)。
在“.zshrc”中:
bindkey -s '\e[25' 'my-command1 ; 我的 command2 \Cm'
... 将 'Shift-F1' 绑定到 'my-command1' 然后是 'my-command2' 并执行它们。
Run Code Online (Sandbox Code Playgroud)仅使用“灰色”键的组合:
键[F1] = '^[[[A' 键[F2] = '^[[[B' 键[F3] = '^[[[C' 键[F4] = '^[[[D' 键[F5] = '^[[[E' 键[F6] = '^[[17~' 键[F7] = '^[[18~' 键[F8] = '^[[19~' 键[F9] = '^[[20~' 键[F10] = '^[[21~' 键[F11] = '^[[23~' 键[F12] = '^[[24~'
键[Shift-F1] = '^[[25~' 键[Shift-F2] = '^[[26~' 键[Shift-F3] = '^[[28~' 键[Shift-F4] = '^[[29~' 键[Shift-F5] = '^[[31~' 键[Shift-F6] = '^[[32~' 键[Shift-F7] = '^[[33~' 键[Shift-F8] = '^[[34~'
键[插入] = '^[[2~' 键[删除] = '^[[3~' 键[主页] = '^[[1~' 键[结束] = '^[[4~' 键[PageUp] = '^[[5~' 键[PageDown] = '^[[6~' 键[向上] = '^[[A' 键[向下] = '^[[B' 键[右] = '^[[C' 键[左] = '^[[D'
key[Bksp] = '^?' key[Bksp-Alt] = '^[^?' key[Bksp-Ctrl] = '^H' console only.
key[Esc] = '^[' key[Esc-Alt] = '^[^['
key[Enter] = '^M' key[Enter-Alt] = '^[^M'
key[Tab] = '^I' or '\t' unique form! can be bound, but does not 'showkey -a'. key[Tab-Alt] = '^[\t'
COMBINATIONS USING THE WHITE KEYS:
Anomalies: 'Ctrl+`' == 'Ctrl+2', and 'Ctrl+1' == '1' in xterm. Several 'Ctrl+number' combinations are void at console, but return codes in xterm. OTOH Ctrl+Bksp returns '^H' at console, but is identical to plain 'Bksp' in xterm. There are no doubt more of these little glitches however, in the main:
White key codes are easy to undertand, each of these 'normal' printing keys has six forms:
A = 'a' (duhhh) A-Shift = 'A' (who would have guessed?) A-Alt = '^[a'
A-Ctrl = '^A' A-Alt-Ctrl = '^[^A' A-Alt-Shift = '^[A' A-Ctrl-Shift = '^A' (Shift has no effect)Don't forget that:
/-Shift-Ctrl = Bksp = '^?' [-Ctrl = Esc = '^[' M-Ctrl = Enter = '^M'
And, we can 'stack' keybindings:
bindkey -s '^Xm' "My mistress\' eyes are nothing like the sun."
... Bind 'Ctrl-X' followed by 'm' to a nice line of poetry.
And we can flirt with madness:
bindkey -s '^Pletmenot' 'Let me not, to the marriage of true minds'
... but you hafta start something like that with a 'modifier' character. Try it, if you like keyboard shortcuts, you can really go to town.
QUESTIONS:
Where is it written that 'Ctrl-Bksp' means one thing at console, another thing in xterm?
Are these assignments changable?
Who designed all this, and what were they thinking at the time?
Why is it 'Alt-Function' to change terminals at a terminal, but 'Alt-Ctrl-Function' to change to a terminal from GUI?
How/where is 'Alt-Ctrl-Delete' defined?
enter code here
在 Unix/Linux 中有许多工具可供您使用,因此它可能有点令人困惑和不知所措。对于初学者,我会使用showkey:
$ showkey -a
Press any keys - Ctrl-D will terminate this program
a 97 0141 0x61
b 98 0142 0x62
c 99 0143 0x63
d 100 0144 0x64
e 101 0145 0x65
f 102 0146 0x66
g 103 0147 0x67
Run Code Online (Sandbox Code Playgroud)
从手册页关于-a:
When in `ascii' dump mode, showkey prints to the standard output the
decimal, octal, and hexadecimal value(s) of the key pressed,
according to he present keymap.
Run Code Online (Sandbox Code Playgroud)
您可以使用xmodmap来获取一些映射:
$ xmodmap
xmodmap: up to 4 keys per modifier, (keycodes in parentheses):
shift Shift_L (0x32), Shift_R (0x3e)
lock Caps_Lock (0x42)
control Control_L (0x25), Control_R (0x69)
mod1 Alt_L (0x40), Alt_R (0x6c), Meta_L (0xcd)
mod2 Num_Lock (0x4d)
mod3
mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
Run Code Online (Sandbox Code Playgroud)
以上不是拼图的所有部分,而是一些额外的信息,可能有助于您找到键绑定和扫描码之间的最终映射。此 U&L 问答中有更多信息,标题为:Linux 中的键映射。
如果只有某种方式将关键字形翻译成“常规”术语:
Run Code Online (Sandbox Code Playgroud)bindkey "Home" beginning-of-line……那我就高兴了。
有infocmp用于描述terminfo条目的实用程序。这对于-L选项又名长 C 变量名特别有用:
$ infocmp -cL
...
key_home= '\EOH'.
key_up= '\EOA'.
key_down= '\EOB'.
key_right= '\EOC'.
key_left= '\EOD'.
key_backspace= '^H'.
key_end= '\EOF'.
...
Run Code Online (Sandbox Code Playgroud)
将此与bindkey输出进行比较
"^[OH" beginning-of-line
"^[OA" up-line-or-history
"^[OB" down-line-or-history
"^[OC" forward-char
"^[OD" backward-char
"^H" backward-delete-char
"^[OE" end-of-line
Run Code Online (Sandbox Code Playgroud)
可以看到他们使用不同的转义符号,但基本上编写一个脚本来连接第二列的infocmp和第一列的bindkey.
如果对特定字符串的含义(如infocmp输出中打印)有任何疑问,可以随时查看提供terminfo完整描述的手册,例如
key_send -> shifted end key
key_sic -> shifted insert-character key
key_dc -> delete-character key
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31009 次 |
| 最近记录: |