Thursday, May 8, 2008

Reverse Lines in a File

You can quickly reverse all lines in a file using the following ex command.


This is particularly useful for files that are in chronological order such as logs or email mbox files. Thanks to Skyler for submitting the tip.


graywh said...

Or you could filter the file through "tac" (the opposite of "cat") by :%!tac.

This assumes you have the GNU coreutils on your path. Windows users will need Cygwin or something comparable.

Anonymous said...

Great tip. Now if only I could remember it, rather than visiting this site once a month.