14.06.2014 Views

vim 101 hacks

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Buyer: xiujuan lu (luxiujuan@gmail.com)<br />

Transaction ID: 85W16630AD8515549<br />

Vim <strong>101</strong> Hacks<br />

www.thegeekstuff.com<br />

:g/^\s*$/d<br />

Delete all empty and blank lines in the file<br />

:g/^$/,/./-j<br />

Reduce multiple blank lines into a single blank lines<br />

:g/pattern/d<br />

Delete the line which has a specific pattern<br />

:g/pattern/ .<br />

w>>filename<br />

Extract lines with specific pattern and write it into<br />

another file<br />

:g/^/m0<br />

Reverse a file<br />

:g/^\s*PATTERN<br />

/exe "norm! I/*<br />

\A */\"<br />

Add a C Style comment ( /* text */ ) to all lines<br />

matching the pattern<br />

Negate Operation Using :g! or :v<br />

Negate operation will match everything except the pattern as explained<br />

below.<br />

Create the following employees.txt file<br />

$ <strong>vim</strong> employees.txt<br />

Emma Thomas:100:Marketing<br />

Alex Jason:200:Sales<br />

Madison Randy:300:Product Development<br />

Sanjay Gupta:400:Support<br />

Nisha Singh:500:Sales<br />

63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!