如何使用shift来选择命令行的一部分(就像许多文本编辑器一样)?
- shift-arrow() {
- ((REGION_ACTIVE)) || zle set-mark-command
- zle $1
- }
- shift-left() shift-arrow backward-char
- shift-right() shift-arrow forward-char
- shift-up() shift-arrow up-line-or-history
- shift-down() shift-arrow down-line-or-history
- zle -N shift-left
- zle -N shift-right
- zle -N shift-up
- zle -N shift-down
- bindkey $terminfo[kLFT] shift-left
- bindkey $terminfo[kRIT] shift-right
- bindkey $terminfo[kri] shift-up
- bindkey $terminfo[kind] shift-down
这假设您的终端在Shift-Arrows上发送一个不同的转义序列来自Arrow发送的转发箭头,并且您的terminfo数据库已正确填充相应的kLFT和kRIT功能,并且您正在使用emacs样式键绑定.
或者,稍微分解代码:
- shift-arrow() {
- ((REGION_ACTIVE)) || zle set-mark-command
- zle $1
- }
- for key kcap seq widget (
- left LFT $'\e[1;2D' backward-char
- right RIT $'\e[1;2C' forward-char
- up ri $'\e[1;2A' up-line-or-history
- down ind $'\e[1;2B' down-line-or-history
- ) {
- functions[shift-$key]="shift-arrow $widget"
- zle -N shift-$key
- bindkey ${terminfo[k$kcap]-$seq} shift-$key
- }
上面是terminfo数据库没有信息的情况下的硬编码序列(使用xterm序列).