Vim Recall繁體中文

Delete every comment-prefixed line

:g/^#/d

Example

Normal 0 / 2
# first
keep
# second
  # indented
Cursor on line 1, column 1

Select matching lines and execute a delete command on them.

Vim registers

" Unnamed register
Characterwise · Uses Yank register 0saved
1 Delete register 1
CharacterwiseEmpty
2 Delete register 2
CharacterwiseEmpty
· space ⇥ tab ↵ line break
Before & after
Before
# first
keep
# second
  # indented
Cursor on line 1, column 1

Vim registers

" Unnamed register
Characterwise · Uses Yank register 0saved
1 Delete register 1
CharacterwiseEmpty
2 Delete register 2
CharacterwiseEmpty
· space ⇥ tab ↵ line break
After
keep
  # indented
Cursor on line 2, column 3

Vim registers

" Unnamed register Changed
Linewise · ↵ marks a line break · Uses Delete register 1#·second↵
1 Delete register 1 Changed
Linewise · ↵ marks a line break#·second↵
2 Delete register 2 Changed
Linewise · ↵ marks a line break#·first↵
· space ⇥ tab ↵ line break

Start in Normal mode, at line 1, column 1 (one-based). The global pattern matches a literal # only at the start of a line. Each matching line is deleted. Type :g/^#/d and press Enter.

Details & Vim help

Example replayed in Vim

Select matching lines and execute a delete command on them.

The global pattern matches a literal # only at the start of a line. Each matching line is deleted.