Reverse sort lines in Vim

November 03, 2018|
1 min read
  • vim

Originally posted by me on Hashrocket TIL

Vim provides sort command for ordering lines in an ascending order, but what if you want to sort the lines in a reverse order?

Linux's tail to the rescue!

First select the lines to be reversed in visual mode with V (big V) then execute this Linux command from Vim's command prompt:

:'<,'>!tail -r

demo


© 2023, Dorian Karter