Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 494
Ravish Chawla Avatar asked Nov 01 '12 14:11

Ravish Chawla


People also ask

How do I switch from insert to command mode in vi?

To enter Insert mode, press i . In Insert mode, you can enter text, use the Enter key to go to a new line, use the arrow keys to navigate text, and use vi as a free-form text editor. To return to Command mode, press the Esc key once.

Which key is used to toggle between the command mode and the insert mode?

But is there a better, or easier, way of switching between command mode and insert mode? Esc is definitely the right key to finish an insert. An insert can be started in various ways.

How do I get out of insert mode?

First, press the Esc key a few times. This will ensure vi is out of Insert mode and in Command mode. Second, type :q! and press Enter. This tells vi to quit without saving any changes.


2 Answers

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.

like image 79
Ricardo Souza Avatar answered Sep 21 '22 15:09

Ricardo Souza


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.

like image 45
Ingo Karkat Avatar answered Sep 18 '22 15:09

Ingo Karkat