Today I Learned
Tidbits of (hopefully) useful information on technologies and tools related to software development.

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 :, type sort, and then press enter.

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!

Learnings sourced by everyone who has taught me, either directly or indirectly. Thanks!

Visit my main site for more, and sometimes longer, content.