Sort and Reverse Sort a Selection of Text or File in Vim
Sorting text is useful, such as sorting dependencies or package imports. Here's how to quickly do it with the built in sort command.
Quick Jump:
This is a 2 minute video going over how to sort (sort
), reverse sort
(sort!
) and uniquely sort (sort u
) text in Vim. You can also combine them
together such as reverse unique sorting text with sort! u
. You can apply this
to a selection of text or the entire file.
# Demo Video
Timestamps
- 0:08 – Sorting a selection of text using the built in sort command
- 0:33 – Reverse sorting a list by adding a bang at the end
- 0:54 – Sorting a unique selection of text
- 1:09 – Combining reverse sort with removing duplicates
- 1:24 – Sorting an entire file with the same sort command
- 1:48 – Checking out sort’s help menu within Vim
Do you prefer Vim’s sort or shelling out to the sort command? Let me know below.