Susensio
Susensio

Reputation: 860

How to exit vim after change command on movement

Let's say I change a word with cw. That leaves me in insert mode. I find it counter intuitive that if I move to a different line, I'm still in insert mode. I would like to exit insert mode without pressing ESC, for example when I move to different line with arrow keys.

How could I do this?

Upvotes: 0

Views: 88

Answers (1)

Martin Tournoij
Martin Tournoij

Reputation: 27822

You can remap the arrow keys to automatically leave insert mode:

inoremap <Up>    <Esc><Up>
inoremap <Right> <Esc><Right>
inoremap <Down>  <Esc><Down>
inoremap <Left>  <Esc><Left>

You may also want to remap <PageDown> and <PageUp>, <ScrollWheelDown>, and <ScrollWheelDown> if you use those.


One downside of this is that it may not work well with some plugins. That is, the plugin will work fine, but it may move the cursor without leaving insert mode as you expect it to. Plus, if you get used to this you may find using a Vim without these mappings (on a server, or someone else's computer) to be frustrating.

Upvotes: 1

Related Questions