vimtricks.wiki Concise Vim tricks, one at a time.

How do I insert the same text at the start of multiple lines using visual block mode?

Answer

<C-v>jjI

Explanation

Visual block mode (<C-v>) lets you select a rectangular region across lines. After making a block selection, pressing I enters insert mode at the start of every selected line simultaneously. Whatever you type is replicated across all lines when you press <Esc>—ideal for adding comment prefixes, indentation, or any repeated prefix without a macro.

How it works

  • <C-v> — enter visual block mode
  • j (repeat as needed) — extend the block downward to cover the target lines
  • I — enter insert mode at the left edge of the block (the first column of the selection)
  • Type your prefix text
  • <Esc> — apply the insertion to all selected lines

Note: A instead of I appends text at the right edge of the block.

Example

Starting with:

foo()
bar()
baz()

Move to f on line 1, press <C-v>jjI// <Esc>:

// foo()
// bar()
// baz()

Tips

  • <C-v>GI selects from the cursor to the last line instantly—useful for large blocks
  • <C-v> with $A appends after the longest line, while A in a fixed-width block appends at the block's right edge
  • To remove the prefix later, <C-v>jj2ld deletes 2 characters from each selected line—no regex needed
  • Works in both Vim and Neovim without any plugins

Next

How do I scroll the view left and right when lines are wider than the screen?