Jay
Jay

Reputation: 9582

VIM: exit insert mode with :normal command

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.

Upvotes: 21

Views: 14873

Answers (3)

too much php
too much php

Reputation: 91018

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

See :help i_CTRL-V.

Upvotes: 26

Luc Hermitte
Luc Hermitte

Reputation: 32936

The maintainable solution would be:

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

... :h :normal

Upvotes: 6

Benoit
Benoit

Reputation: 79185

:imap will not trigger in command mode. Use :cmap or better, :cnoremap.

And as too much php said, CTRL-V makes it possible to insert raw characters in insert mode or command line editing.

Upvotes: 0

Related Questions