Reputation: 62797
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.
Upvotes: 1
Views: 105
Reputation: 172590
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".
Upvotes: 2