Other ways to exit Insert mode besides Escape

2017-04-26 11:09:42

The primary reason I like vim over emacs is that my hand movement distance away from the home row is very low (even as a programmer). However, the one main time that I do this is leaving insert mode, by pressing Escape.

I recently learned that I can use Ctrl+C to leave insert mode as well. However, this isn't really an improvement.

How can I exit insert mode without having my hands leave the home row, and without massively impacting what I have the ability to type? Note: I use a mostly vanilla vim with a dvorak keyboard layout, though I'd love to hear solutions for a qwerty layout as well.

A common binding you'll see is jj, because it works well for QWERTY layouts if you use home row positioning.

inoremap jj

In that case, to type jj - you should wait for 1 sec (by default) between type the second character. (see :help 'timeout' for details)

There is also c-o which will take you out of insert, letting you do one normal command, and then put you right bac

  • A common binding you'll see is jj, because it works well for QWERTY layouts if you use home row positioning.

    inoremap jj

    In that case, to type jj - you should wait for 1 sec (by default) between type the second character. (see :help 'timeout' for details)

    There is also c-o which will take you out of insert, letting you do one normal command, and then put you right back into insert.

    http://vim.wikia.com/wiki/Avoid_the_escape_key

    2017-04-26 11:26:14
  • Beside the built-in alternatives and to key cited by others, another popular solution is to remap as an additional Escape.

    This both on a Qwerty and Dvorak keyboard.

    This way you can press Esc very easily with the left little finger, without removing hands from the HomeRow (incidentally, CapsLock is where Escape used to be on the keyboards when vi was invented).

    Remapping can be done:

    on Windows using AutoHotKey utility;

    on Mac using the KeyRemap4MacBook utility and others;

    on Linux, varies according to the Desktop Environment. For example on Linux Mint/Cinnamon is just a matter of selecting the

    proper option in Menu->Keyboard->Keyboard Layouts->Caps Lock behavior. Alternatively, but less easily, it can be remapped at Xorg level using the xmodmap program and having it run the following .Xmodmap file:

    clear Lock

    keycode 0x42 = Escape

    The system can be setup to automatically run it at every login by placing strategically the following shell scri

    2017-04-26 11:26:54
  • The mappings that I use are:

    inoremap jk

    inoremap kj

    This way, you can simply hit j and k at the same time, without having to worry about which one you press first.

    2017-04-26 11:42:55
  • and are two native alternatives to .

    See :help i_ and :help i_ctrl-c which explains the difference between and .

    2017-04-26 11:55:45
  • FWIW I use:

    :map! ;l ^[

    :vmap ;l ^[

    It feels similar to hitting Return.

    I use ; as the leader for other Insert-mode mappings too.

    The only time I've needed to type ';' + letter is when code golfing; I've not had any conflicts otherwise.

    2017-04-26 12:08:50
  • I've been using Ctrl+3 since quite some time, I find it easier to type than most alternatives and seems to work nicely (at least on Linux).

    My Caps Lock is mapped to Ctrl, so it's very comfy to type it.

    I tried using Ctrl+c for some time, but I had some issues with it which I don't recall exactly now, but I wasn't getting the exact same behavior as Esc, like I get now with Ctrl+3.

    2017-04-26 12:17:18
  • If you have an US English keyboard, pressing Ctrl-[ is equivalent for pressing Esc. This provides an easy way to exit from insert mode. Alternatively use Ctrl-c.

    If you've vim in easy mode (-y), then you've to press Ctrl-l (Control-L) to exit insert mode.

    There is also Ctrl+o which will only temporary exit insert mode just to execute one command and return back to insert mode (see: :help i_CTRL-O)

    Or Ctrl+r, but it's only for inserting content of register or expression, e.g. Ctrl+r, =5*5 (see: :help i_CTRL-R, :help c_CTRL-R and stackoverflow post).

    Read more at: Avoid the escape key at vim wikia

    2017-04-26 12:23:24
  • In terminal vi and Vim,

    alt + single-normal-mode-key will work for quick edits in most terminals.

    This works because most terminals send the alt modifier as the escape character. For example, when you type alt+k the terminal emulator sends two character to the running program: esc, k. Vi and Vim interpret this as you would expect; it leaves insert mode (because of the escape) and executes the normal mode command (in the example, moving the cursor up one line).

    This can be a convenient way to exit insert mode if your keyboard has the alt key next to the space bar (so that it can be pressed by thumb, leaving your fingers on the home row), so long as you are using a terminal emulator with this behaviour and don't mind running a normal mode command.

    2017-04-26 12:39:10
  • You can map Caps Lock to Control without using any external program:

    In Mac OS X visit System Preferences > Keyboard -> Modifier Keys

    In Linux execute: setxkbmap -option caps:ctrl_modifier

    In Windows edit your registry.

    This brings Control onto the home row, making it easier to press all Control modified strokes, including Ctrl-[ and Ctrl-C which both exit Insert mode in Vim.

    Alternatively, at the bottom of his answer Giovanni suggests to map Caps Lock to perform both Control and Escape depending on the length of press, but this requires installing extra software.

    Ctrl-[ is the preferred alternative, since it always works like Escape.

    One noticeable difference with Ctrl-C is that when leaving an edit in blockwise visual mode, Ctrl-C will keep the changes you made on the current line, but will not repeat the changes over the other lines in the block, which is the point of that mode.

    It also won't check for abbreviations, or trigger the InsertLeave event. See :help

    2017-04-26 12:39:38
  • I would suggest using my plugin vim-easyescape.

    Plug "zhou13/vim-easyescape"

    let g:easyescape_chars = { "j": 1, "k": 1 }

    let g:easyescape_timeout = 100

    cnoremap jk

    cnoremap kj

    The problem with a simple map sequence inoremap jj is that Vim will pause whenever you type j or k in insert mode (it is waiting for the next key to determine whether to apply the mapping). The pause causes visual distraction which you may or may not notice. vim-easyescape does not have such problem and supports custom timeout.

    2017-04-26 12:48:25