Reverse sort lines in Vim

November 03, 2018

  • 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


Written by Dorian Karter, a Sr. Software Engineer
Github | Twitter

© 2021, Dorian Karter