How do I delete each line matching a pattern along with a fixed number of lines that follow it?
:g/pattern/.,+2d
Inside a :global command, .
command-line #ex-commands #global #delete #editing #command-line
:g/pattern/.,+2d
Inside a :global command, .
command-line #ex-commands #global #delete #editing #command-line
d3aw
Most Vim users know you can put a count before an operator (3dw) or use a text object once (daw).
editing #text-objects #editing #delete #normal-mode #motions
<C-u> in insert mode
Pressing while in insert mode deletes all characters entered since you last entered insert mode on the current line.
"Ay{motion}
Using an uppercase register letter with any operator appends to the register instead of replacing it.
das
Vim defines a sentence as text ending with .
editing #editing #text-objects #delete #normal-mode #motions
"_d{motion}
Vim's black hole register (") acts as a write-only sink: anything sent to it is discarded without affecting any other register, including the unnamed register (
d/{pattern}<CR>
Vim lets you use a / search as a motion for any operator.
"1p then u then . to cycle
Vim stores your last 9 deletions in numbered registers "1 through "9.
c in visual mode
Select text visually, then press c to delete the selection and enter insert mode.
d in visual mode
Select text visually and press d to delete the selection.
:call DeleteHiddenBuffers()
Define a function or use a plugin.
:bd 3
Use :bd (bdelete) followed by the buffer number.
"_dd
Use the black hole register " before a delete command.
qa/^$/\ndd@aq
Record a macro that searches for blank lines, deletes them, and recurses.
qa0dwjq
Record a macro that goes to the start of line with 0, deletes the first word with dw, and moves down with j.
qad/pattern\nq
Record a macro that deletes from the cursor to the next match of a pattern using d/pattern.
"-p
The small delete register ("-) captures text from delete operations that are less than one line — like dw, x, dt.
<C-h> / <C-w> / <C-u>
Vim provides three levels of deletion directly in insert mode, so you don't need to switch to normal mode for small corrections.
"1p ... "2p ... "9p
Vim maintains a numbered register history from "1 through "9 that stores your last 9 deletes and changes.
<C-w>
Pressing in insert mode deletes the word before the cursor instantly, without requiring you to switch to normal mode.