rwblickhan.org
Fiction
Essays
Technical
Misc
Logs
Gallery
← Technical

TIL: :sort in vim

vim has a built-in sorting function. Specify a range or a visual selection and run :sort in command mode to sort the given lines. You can also do things like:

  • :sort! to invert the order.
  • :sort i to ignore case.
  • :sort u to deduplicate the lines.
  • :sort n or :sort f for integer or float numeric sorting; in particular, these will sort by the first number on each line.
  • :sort /pattern/ to ignore a pattern and :sort /pattern/ r to sort based on pattern.

References

  • “Sorting text”
  • “A Vim Guide for Advanced Users”, “Sorting Text”