98

I just started using Vim as an IDE. I was using it as a test editor for a while now, so I didn't have to go to command mode very often. But, since I program in Java, I have to go to command mode to make the file, compile/run it... etc.

The problem is: I need a good way to switch between the two modes.

I looked online and it says that the <Esc> key is supposed to do that, but that doesn't work for me (maybe it's not for gVim? I don't know why.)

I have to press CTRLO every time to go to command mode; the escape key works from that mode... it brings me back to insert mode. But is there a better, or easier, way of switching between command mode and insert mode?

Peter David Carter
  • 2,548
  • 8
  • 25
  • 44
Ravish Chawla
  • 999
  • 1
  • 6
  • 4
  • 2
    Esc is definitely the right key to finish an insert. An insert can be started in various ways. Lowercase i to start inserting at your cursor, uppercase I to start inserting at the beginning of the line, etc. – Vaughn Cato Nov 01 '12 at 14:18
  • Starting from an empty file, the following characters should give you a file with the word "hello" in it: `ihello:w hello.txt` – Vaughn Cato Nov 01 '12 at 14:21
  • 11
    `ctrl-[` works as a substitute for Esc on many keyboards. – Vaughn Cato Nov 01 '12 at 14:23

8 Answers8

120

Pressing ESC quits from insert mode to normal mode, where you can press : to type in a command. Press i again to back to insert mode, and you are good to go.

I'm not a Vim guru, so someone else can be more experienced and give you other options.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ricardo Souza
  • 16,030
  • 6
  • 37
  • 69
58

Looks like your Vim is launched in easy mode. See :help easy.

This happens when Vim is invoked with the -y argument or as evim, or maybe you have a :set insertmode somewhere in your .vimrc configuration. Find the source and disable it; temporarily this can be also done via Ctrl + O :set noim Enter.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
30

This has been mentioned in other questions, but ctrl + [ is an equivalent to ESC on all keyboards.

Community
  • 1
  • 1
emegolf123
  • 401
  • 4
  • 3
5

Using jj

In my case, the .vimrc (or in gVim it is in _vimrc) setting below.

inoremap jj <Esc>   """ jj key is <Esc> setting
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
StarMomo
  • 115
  • 2
  • 7
  • This is a common remapping. I find it has a slight delay as it waits for additional character input. Alternatively, remap your capslock key to esc using something like KeyRemap4MacBook on a Macbook: https://github.com/tekezo/KeyRemap4MacBook – Koobz Mar 26 '14 at 10:10
  • i found it easier to remap tab to esc :3 – Fuseteam Oct 30 '19 at 17:44
4

Coming from emacs I've found that I like ctrl + keys to do stuff, and in vim I've found that both [ctrl + C] and [alt + backspace] will enter Normal mode from insert mode. You might try and see if any of those works out for you.

maxorcist
  • 349
  • 4
  • 8
  • 1
    Saved my life on a cpanel terminal emulator, where ESC is not working. thx ;) – zsd Nov 05 '21 at 09:19
4

For me, the problem was that I was in recording mode. To exit from recording mode press q. Then Esc worked as expected for me.

betontalpfa
  • 3,454
  • 1
  • 33
  • 65
1

You can use Alt+H,J,K,L to move cursor in insert mode.

Khoi Hoang
  • 19
  • 1
0

There is also one more solution for that kind of problem, which is rather rare, I think, and you may experience it, if you are using vim on OS X Sierra. Actually, it's a problem with Esc button — not with vim. For example, I wasnt able to exit fullscreen video on youtube using Esc, but I lived with that for a few months until I had experienced the same problem with vim.

I found this solution. If you are lazy enough to follow external link, switching off Siri and killing the process in Activity Monitor helped.

Community
  • 1
  • 1
oleander
  • 1
  • 1