Selecting Lines for Operations
:1,20s/hello/world # search/replace only for first 20 lines
:20,$s/hello/world # search/replace for lines from 20 onwards
:$-20,$s/hello/world # search/replace for last 20 lines of file
:.,.+5s/hello/world # search/replace from current line to 5 lines down
Search And Replace
:s@hello@<p>hello</p> # if / occurs in search/replace string
Matching and Deleting
:g/pattern/d # delete matched lines
:g/pattern/-1d # delete line before each match
:g/pattern/+1d # delete line after each match
:g/pattern/-1,+1d # delete from line before to line after
:%d # delete all lines (useful to abort Ctrl+X+E
:.,$d # delete all lines from current onwards
:1,.d # delete all lines from start to current