History Report a problem
Article Edit this page Discussion

Use the return key to get out of insert mode

From Vim Tips Wiki

(Redirected from VimTip783)
Jump to: navigation, search

Tip 783 Previous TipNext Tip

Created: September 6, 2004 Complexity: basic Author: Klaus Voelker Minimum 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>

[edit] 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>

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pushing Daisies
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Godzilla
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Use the return key to get out of insert mode"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation


.