O'Reilly logo

Mastering Vim by Ruslan Osipov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interacting with Vim

The execute command lets you parse and execute a string as a Vim command. For example, the two following statements will produce equivalent results:

echo animal . ' says hello'execute 'echo ' . animal . ' says hello'

You can use normal to execute keys just like the user would in normal mode. For instance, if you wanted to search for a word cat and delete it, you could do this:

normal /cat<cr>dw
<cr> here needs to be typed with Ctrl + v, followed by the Enter key. However, execute "normal /cat<cr>dw" would use the literal string <cr> to represent Enter key press. Just a quirk to be aware of.

Running normal like this will respect the user's mappings, so if you want to ignore custom mappings, you could use normal!:

normal! ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required