103

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?

3
  • 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. Commented Nov 1, 2012 at 14:18
  • Starting from an empty file, the following characters should give you a file with the word "hello" in it: ihello<ESC>:w hello.txt<ENTER> Commented Nov 1, 2012 at 14:21
  • 11
    ctrl-[ works as a substitute for Esc on many keyboards. Commented Nov 1, 2012 at 14:23

8 Answers 8

124

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.

1
  • 3
    For most of us, but the accepted answer had the answer to the specific problem. Commented Aug 26, 2018 at 5:30
59

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.

4
  • I think that was it. I had insert-mode enabled in my file. After I removed it, the escape-key works perfectly. Thanks! Commented Nov 1, 2012 at 14:45
  • 12
    this is easy mode!?
    – Stachu
    Commented Sep 16, 2017 at 2:15
  • 7
    Vim easy mode, now that's an oxymoron. Is that where it's possible to exit vim?
    – Davos
    Commented Dec 19, 2017 at 15:03
  • 1
    @Davos that's the mode where it is started in insert mode, so ironically it's a mode where it's not possible to exit vim :p "normal mode" is way easier just alt+:,x XD
    – Fuseteam
    Commented Oct 30, 2019 at 17:43
35

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

2
  • I never knew that, useful when escape key is not supported
    – KRoy
    Commented Feb 16, 2018 at 3:03
  • Wow, thanks for that information! Tmux copying keystroke sequence now makes much more sense. Commented Oct 3, 2018 at 9:12
6

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.

1
  • 2
    Saved my life on a cpanel terminal emulator, where ESC is not working. thx ;)
    – zsd
    Commented Nov 5, 2021 at 9:19
6

Using jj

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

inoremap jj <Esc>   """ jj key is <Esc> setting
2
  • 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: github.com/tekezo/KeyRemap4MacBook
    – Koobz
    Commented Mar 26, 2014 at 10:10
  • i found it easier to remap tab to esc :3
    – Fuseteam
    Commented Oct 30, 2019 at 17:44
5

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.

2

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

4
  • 1
    No, you can't. That is probably a remap of your configuration. Commented Aug 26, 2018 at 5:32
  • 2
    @SaulAxelMartinezOrtiz yes you can, tho technically it exits normal mode after which you can move around in normal mode :p
    – Fuseteam
    Commented Oct 30, 2019 at 17:45
  • 1
    just to add same way you can do Alt+/ Alt+? Alt+: and so on Commented Jun 2, 2023 at 9:53
  • @SaulAxelMartinezOrtiz something might catch your input with Alt key thus making it not working in vim Commented Nov 23, 2023 at 11:55
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.