Vim: why doesn't ":normal! i" enter insert mode?

The normal command considers ending in insert mode as an incomplete command and aborts. From help normal:

{commands} should be a complete command. If {commands} does not finish a command, the last one will be aborted as if <Esc> or <C-C> was typed. The display isn't updated while ":normal" is busy. This implies that an insert command must be completed (to start Insert mode, see :startinsert)

:startinsert might be the command you are looking for.

:normal A can be achieved by appending a bang (!) to startinsert, as suggested by Ingo Karkat. From help startinsert:

When the ! is included it works like "A", append to the line.


In addition to already mentioned startinsert you can use feedkeys():

call feedkeys('A', 'n')

will do what you want, but the key you added this way will only be processed after execution of current script/function/mapping/etc is finished.


Instead of :normal A, use :startinsert! (with !). It's mentioned in the help.

For :normal a, move the cursor to the right, then do :startinsert.

Tags:

Vim

Insert

Mode