Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: exit insert mode with :normal command

Tags:

vim

macvim

When I go into insert mode with the :normal command (:normal i) for example, how do I exit insert mode?

If I press <Esc>, or <c-c>, or <c-[>, VIM exits command mode and I can't run my :normal command.

I put imap <c-e> <Esc> in my .vimrc but when I type <c-e> in command mode, nothing gets inserted. I can't figure out how to enter a "control e" in command mode.

<c-o> works, for example :normal Ihello<c-o>Aworld but sometimes I want to do more than one command in normal mode.

I know I can use a macro, but I want to know how to do it with :normal.

like image 488
Jay Avatar asked Oct 24 '10 22:10

Jay


People also ask

How do I get out of insert mode in 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.

How do I get out of insert mode?

Press the "Ins" key to toggle overtype mode off. Depending on your keyboard model, this key may also be labeled "Insert." If you simply want to disable overtype mode but keep the ability to toggle it back on, you are done.

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.

How do I switch to normal mode in vim?

The most commonly used command to enter in to insert mode is “i”. To shift back to normal mode, press Esc. To switch to the visual mode from Normal mode, different commands are v, V, Shift + v, and Ctrl + v. The most commonly used command to enter in to insert mode is “v”.


2 Answers

To add a literal <ESC> to your command, while in insert mode, press CTRL+V then <ESC>.

See :help i_CTRL-V.

like image 62
too much php Avatar answered Oct 20 '22 11:10

too much php


The maintainable solution would be:

exe "normal! Ihello\<c-o>Aaworld\<esc>"

... :h :normal

like image 45
Luc Hermitte Avatar answered Oct 20 '22 09:10

Luc Hermitte