How do I switch between command and insert mode in Vim?

VimInsertCommand

Vim Problem Overview


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?

Vim Solutions


Solution 1 - Vim

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.

Solution 2 - Vim

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.

Solution 3 - Vim

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

Solution 4 - Vim

Using jj

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

inoremap jj <Esc>   """ jj key is <Esc> setting

Solution 5 - Vim

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.

Solution 6 - Vim

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.

Solution 7 - Vim

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.

Solution 8 - Vim

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRavish ChawlaView Question on Stackoverflow
Solution 1 - VimRicardo SouzaView Answer on Stackoverflow
Solution 2 - VimIngo KarkatView Answer on Stackoverflow
Solution 3 - Vimemegolf123View Answer on Stackoverflow
Solution 4 - VimStarMomoView Answer on Stackoverflow
Solution 5 - VimmaxorcistView Answer on Stackoverflow
Solution 6 - VimbetontalpfaView Answer on Stackoverflow
Solution 7 - VimoleanderView Answer on Stackoverflow
Solution 8 - VimKhoi HoangView Answer on Stackoverflow