vim Using Normal Mode Commands in Vimscript


Since a Vimscript file is a collection of Command mode actions, the user needs to specify that the desired actions should be executed in normal mode.

Therefore executing a normal mode command like i, a, d etc. in Vimscript is done by prepending the command with normal:

Going to the bottom of the file and selecting the last 5 rows:

normal GV5k

Here the G instructs vim to change the cursor position to the last row, the V to go to linewise visual mode , and the 5k to go 5 rows up.

Inserting your name at the end of the row:

normal ABoris

where the A puts the editor in insert mode at the end of the row and the rest is the text to insert.