Vim Tips Wiki
Advertisement
Tip 783 Printable Monobook Previous Next

created September 6, 2004 · complexity basic · author Klaus Voelker · version 5.7


I found myself spending way too much time in insert mode, because it takes so much effort to hit <ESC>, or alternatively <C-[>. To train myself to use insert mode only for what it's meant for - namely inserting text - I wanted to make it as easy as possible for myself to get out of insert mode.

My solution: map <CR> to <ESC>! Pressing the return key at the end of an insert operation feels very natural, and it is one of the more accessible keys on the keyboard. For inserting multiline text, you can use shift-return, which really doesn't take that much getting used to.

If you want to give it a try, put the following in your vimrc:

inoremap <CR> <ESC>

Comments

I guess it will be better to set <shift><cr> to escape can anyone suggest a way to do the same


Sure; simply change it to:

:inoremap <S-CR> <ESC>

(This works in the GUI-versions on Linux (GTK) and OS X, but in neither terminal version.)


Interesting -- this tip concerns the situation in which one is doing mostly non-insert mode operations.

The situation when creating a new file is the opposite: one is mostly in insert mode. For such situations, consider VimTip154 which is based on ctrl-o in insert mode (:help i_ctrl-o).

Also: it might be possible to define a map that will take one from normal mode to insert mode and bring one back to normal mode on hitting return; but will leave return to its usual behavior when going to insert mode in the usual ways. This would be the "normal version of i_ctrl-o".


Also consider remaping caps lock to escape, via xmodmap (if I recall correctly) or registry entry.

That is, something similar to the below:

remap_capslock_to_esc.reg
>>
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00
<<

I find this works VERY well.


  1. How about 'idle' -> <ESC>.
  2. How about [^isprint] -> <ESC><key-pressed>

Advertisement