David Nash

Wordpress Guru Sydney

Assorted Handy vim Commands, Part 1

Posted on January 28, 2009

To reverse the order of lines, eg 1-5
: 1,5 g/^/m0
For example,

one
two
three
four
five

becomes

five
four
three
two
one

To remove blank lines
: %g/^$/d

Delete all lines that don’t contain “string”
: %v/string/d

  1. Gage says:

    Nice! I love vim, I wish you would explain how the lines switching one works but ah well.

    Part 2 coming?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>