Pergunta

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.

Foi útil?

Solução

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"'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top