自动关闭GNU Readline [英] Autoclose GNU Readline

查看:107
本文介绍了自动关闭GNU Readline的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用各种基于GNU Readline的CLI,这将极大地 如果可以使用方括号和引号,可以加快我的速度 键入时自动关闭.

因此在Bash(或其他CLI)上键入'( 在结尾加上引号或方括号''()并放置光标 在写作之间.

我已经环顾了很长时间,试图找出与之相关的任何内容 (例如~/.inputrc设置),但没有找到任何内容,我想知道这是否是 完全可以实现的.任何意见将不胜感激.

解决方案

有点棘手,但可行.作为bash命令:

bind '"(" "\C-v()\e[D"'
bind '"\"" "\C-v\"\C-v\"\e[D"'

作为.inputrc中的设置(因此,使用readline的任何程序都会获得该行为):

"(": "\C-v()\e[D"
"\"": "\C-v\"\C-v\"\e[D"

您可以在每个键前面加上Control-v,以键入普通"引号和左括号,而不会触发自动关闭行为.

以上假设Emacs的键盘绑定.对于vi绑定,请使用

bind '"(": "\C-v()\ei"'
bind '"\"" "\C-v\"\C-v\"\ei"'

"(": "\C-v()\ei"
 "\"": "\C-v\"\C-v\"\ei"

本质上,只需将[D替换为i;无需发送转义序列以将光标向左移动,只需在插入括号/引号后发送\e使其回到命令模式,然后重新进入插入模式,即可将光标置于刚键入的字符内.

Working on various GNU Readline-based CLIs and it would dramatically speed me up if there was a way to have brackets and quotes automatically closed when you type.

Thus typing a ' or ( on Bash (or other CLIs) would actually append the closing quote or bracket '' or () and place the cursor inbetween for writing.

I've looked around for quite some time trying to find out anything related (e.g. ~/.inputrc setting), but didn't find anything and I wonder if that's at all achievable. Any comments would be appreciated.

解决方案

It's a bit tricky, but doable. As a bash command:

bind '"(" "\C-v()\e[D"'
bind '"\"" "\C-v\"\C-v\"\e[D"'

As a setting in .inputrc (so any program using readline gets the behavior):

"(": "\C-v()\e[D"
"\"": "\C-v\"\C-v\"\e[D"

You can prefix each key with Control-v to type "plain" quotes and left parentheses without triggering the auto-close behavior.

The above assumes Emacs keybindings. For vi bindings, use

bind '"(": "\C-v()\ei"'
bind '"\"" "\C-v\"\C-v\"\ei"'

or

"(": "\C-v()\ei"
 "\"": "\C-v\"\C-v\"\ei"

Essentially, just replace the [D with i; instead of sending the escape sequence to move the cursor left, just send \e to drop back into command mode after inserting the parentheses/quotes, then re-enter insert mode, which should position the cursor inside the characters just typed.

这篇关于自动关闭GNU Readline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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