zsh zle 移位选择 [英] Zsh zle shift selection

查看:20
本文介绍了zsh zle 移位选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 shift 来选择命令行的一部分(就像在许多文本编辑器中一样)?

How to use shift to select part of the commandline (like in many text editors) ?

推荐答案

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 样式的键绑定.

That assumes your terminal sends a different escape sequence upon Shift-Arrows from the one sent upon Arrow and that your terminfo database is properly populated with corresponding kLFT and kRIT capabilities, and that you're using emacs style key binding.

或者,稍微分解代码:

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

Above, hardcoded sequences for cases where the terminfo database doesn't have the information (using xterm sequences).

这篇关于zsh zle 移位选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆