Tip: #783 - Use the return key to get out of insert mode
Created: September 6, 2004 17:45 Complexity: basic Author: Klaus Voelker Version: 5.7 Karma: 8/6 Imported from: Tip#783
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
Anonymous , September 6, 2004 21:38
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.)
niklasl
, September 7, 2004 2:08
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".
anon , September 7, 2004 14:15
Also consider remaping caps lock to escape, via xmodmap (if I recall correctly) or registry entry.
I.e. 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.
sreny at rpyrpgvpjvmneq dot pbz (Rot13ed) , September 7, 2004 16:45
1. How about 'idle' -> <ESC>. 2. How about [^isprint] -> <ESC><key-pressed>
I would be happier, if vim just did very smart context-completions, like it knew what I was reading in any window, and provided completion closest to what is in my mind (what I am reading, and what I typed recently).
- PGM.
perci merci from kalyan , September 7, 2004 17:02
- inoremap <S-CR> <ESC> does not work in terminal version
Any help to make it work ?
Anonymous , September 7, 2004 18:12
perci, you do know about ^p, correct?
C52MKIV--AT--hotmail.com , September 9, 2004 19:25
Any help getting the windows key on my keyboard to map to escape for the terminal version of VIM under Linux?
-noah
noahjscales--AT--yahoo.com , September 10, 2004 16:13