How to Sort Lines in Vim
November 29, 2020 - Vim
You can use the built-in sort utility!
To perform a sort, first select the lines you want to sort using visual mode. Afterwards, press
sort, and then press
Note that the default sort is based on unicode characters so the results may be unexpected (it accepts an optional regex argument to help with that!)
There are some neat options like
u for removing duplicate lines,
n for numeric sort, and
sort! for sorting in reverse.
Want to improve this post? Feel free to submit a pull request!