Вопрос

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