1

Question inspired by this answer:

Is there a way to configure vim so, that in insert mode moving the cursor outside currently edited area (cursor keys, ctrl-o prefix, whatever) will return to normal mode, but just editing the currently inserted text will stay in insert mode?

How?

Alternatively, how to prevent cursor from leaving the currently inserted text in insert mode, requiring Esc first.


Some examples to clarify:

ibsr<left><bs>a<right>

stays in insert mode, but

ibar<up>
iba<left><left><left>
iba<right>

would all return to normal mode.

Community
  • 1
  • 1
hyde
  • 60,639
  • 21
  • 115
  • 176

1 Answers1

2

There's no quick-and-easy built-in configuration for that; the closest is the default (empty) value of 'backspace', which disallows <BS>, <Del>, <C-W> and <C-U> outside of the current insert.

That said, nothing prevents you from writing a custom plugin. It would have to :inoremap <expr> all the movement keys (like <Left>, <Up>, etc.) and test for the cursor leaving the current line / whatever you consider the current edit (unfortunately, the '[ and '] marks are only set after insert mode is left), then returning the original key followed conditionally by <Esc>.

Doable, but quite involved. Do you really need the editor to give you those training wheels? A little self-restraint and reflection while editing should already teach you to use Vim "right".

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Ok, sounds like it's not worth the effort. I was just hoping there'd be an easy way (because of the whole "stay the hell out of vim insert mode" faction). This would also effectively solve one of my pet peeves with vim, no way to just *insert* a single character with two keypresses (instead of currently required three). Oh well. – hyde Oct 25 '13 at 06:59
  • 1
    To insert a single character, try this: `nnoremap i$r` – Ingo Karkat Oct 25 '13 at 07:05