I would like to do something like this in bash:

bind -m vi-insert '"{" "\C-v{}\e[D"'

This works except after autoclosing } and put the cursor in the middle, it also exits the insert mode, which is very annoying.

有帮助吗?

解决方案

The given macro assumes Emacs key bindings; after inserting the braces, the escape sequence \e[D moves the cursor one cell to the left, positioning it between the braces. In vi mode, the \e has the effect of exiting insert mode and going back to command mode. A simple fix is to leave insert mode, then immediately re-enter, which will also reposition the cursor where you want it; no explicit cursor movement is necessary.

bind -m vi-insert '"{" "\C-v{}\ei"'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top