Autoclose GNU Readline

我怕爱的太早我们不能终老 提交于 2019-11-29 08:10:50

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.

Doing exactly what you want is impossible, but there is a work around. Put this in inputrc:

"\C-x\"": "\"\"C-b"

Run:

info readline "comm" "readline init" "sample"

for the whole sample.

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