Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

How to prevent the cursor from moving back one character on leaving Insert mode in Vim?

Is it possible to cancel the said behavior?

A task for extra credit: Figure out a way to force Vim to refresh the cursor position immediately after exiting Insert mode.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 <silent> <Esc> <Esc>`^

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...