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 modej(repeat as needed) — extend the block downward to cover the target linesI— 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>GIselects from the cursor to the last line instantly—useful for large blocks<C-v>with$Aappends after the longest line, whileAin a fixed-width block appends at the block's right edge- To remove the prefix later,
<C-v>jj2lddeletes 2 characters from each selected line—no regex needed - Works in both Vim and Neovim without any plugins