Display context (5 lines) for all occurences of a pattern
:g/<pattern>/z#.5
:g/<pattern>/z#.5|echo "=========="
<< same as first, but with some beautification >>
Delete all lines matching a pattern
:g/<pattern>/d
Delete all blank lines (just an example for above)
:g/^\s*$/d
Double space the file
:g/^/pu =\"\n\"
:g/^/pu _
<< the above one also works >>
Copy all lines matching a pattern to end of file
:g/<pattern>/t$
Yank all lines matching a pattern to register 'a'
0"ay0:g/<pattern>/y A
Increment the number items from current line to end-of-document by one
:.,$g/^\d/exe "normal! \<c-a>"
Comment (C) lines containing "DEBUG" statements
g/^\s*DEBUG/exe "norm! I/* \<Esc>A */\<Esc>"
A Reverse lookup for records
(eg: An address book, with Name on start-of-line and fields after a space)
:g/<patern>?^\w?p "if only name is interested
:g/<patern>/ka|?^\w?p|'ap "if name and the lookup-line is interested
:g/<patern>/?^\w?|+,/^[^ ]/-1p "if entire record is interested
Reverse a file (just to show the power of 'g')
:g/^/m0