Prevent cursor from moving back one character on insert mode exit

前端 未结 6 1363
南笙
南笙 2020-11-29 21:35

...how would you do it?

task for extra credit: figure out a way to force vim to refresh the cursor position immediately after exiting insert mode

6条回答
  •  天命终不由人
    2020-11-29 22:24

    Although I would not recommend changing the default cursor mechanics, one way of achieving the behavior in question is to use the following Insert-mode mapping.

    :inoremap   `^
    

    Here the Esc key is overloaded in Insert mode to additionally run the `^ command which moves the cursor to the position where it had been the last time Insert mode was left. Since in this mapping it is executed immediately after leaving Insert mode with Esc, the cursor is left one character to the right as compared to its position with default behavior.

    Unlike some other workarounds, this one does not require Vim to be compiled with the +ex_extra feature.

提交回复
热议问题