How to insert text at beginning of a multi-line selection in vi/Vim

  1. Press Esc to enter ‘command mode’
  2. Use Ctrl+V to enter visual block mode
  3. Move Up/Downto select the columns of text in the lines you want to
    comment.
  4. Then hit Shift+i and type the text you want to insert.
  5. Then hit Esc, wait 1 second and the inserted text will appear on every line.

For further information and reading, check out “Inserting text in multiple lines” in the Vim Tips Wiki.

Leave a Comment