Assorted Handy vim Commands, Part 1

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

Share:
  • del.icio.us
  • Facebook
  • Google
  • E-mail this story to a friend!
  • Technorati
  • TwitThis

One Comment

  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