If you need to add the same text on multiple lines e.g. comment out multiple lines, insert semi-colons etc, then visual block mode is your friend!
Let’s take a look at the following ansible YAML playbook :
Assuming we want to comment out the nginx, php-fpm and wordpress roles (lines 12 – 14). In YAML the comment character is ‘#’.
We need to go to line 12, start visual block mode and select the 3 lines, insert a ‘#’ char at beginning of line, exit to normal mode.
In vim you start visual block by pressing <Ctrl+v>. Now these commands:
12G <Ctrl+v>jj$ I# <Esc>
Lines 12 to 14 should now be preceeded by a ‘#’. This is because in visual block mode all insert commands are repeated for each line. Nice!