Vim Recall繁體中文

Add a prefix to several lines

<C-v>2jI# <Esc>

Example

Normal mode on a in alpha. Lines: alpha, beta, gamma.

Before
alpha
beta
gamma
Cursor on line 1, column 1
  1. <C-v>2j First column selected · three-line Visual block
  2. I# <Esc> Prefix all three lines with # and a space
After
# alpha
# beta
# gamma
Cursor on line 1, column 1
Details & Vim help

Insert the same text at the left edge of a Visual block.

Comment or label aligned lines in one insertion.

The repeated insertion appears after leaving Insert mode. Short lines before the block’s start can be skipped; tabs and virtualedit affect column behavior. Ctrl-v may be remapped by a platform configuration.

Try it in Vim

  1. Start at the a in alpha and press Ctrl-v, then 2j.
  2. Press uppercase I and type # followed by a space.
  3. Press <Esc> to apply the insertion to the selected rows.