vi tips and tricks

Sort from within vi

:%sort - Sort whole file

:%sort! - Sort file - in reverse

:%!sort - Sort using external sort utility

:%!sort -M - Sort using external sort utility respecting month-name order

:sort n - Numeric sort

:{range}sort - Sort range (eg: :1,15sort will sort lined 1-15)

:{range}sort u - Sort and keep only unique lines

 

Source: https://vim.fandom.com/wiki/Sort_lines