Sort a list and remove duplicate lines
:%sort u
Example
Normal mode. Lines: pear, apple, pear, banana.
pear
apple
pear
banana- :%sort u<CR> Sorted, duplicates removed · apple, banana, pear
apple
banana
pearDetails & Vim help
Sort the chosen lines and keep one copy of identical lines.
Clean repeated entries in a scratch list.
Sorting changes line order. u removes consecutive identical whole lines after sorting, ignoring case with i. Equal numeric keys with n do not make different lines duplicates.
Try it in Vim
- Run :%sort u<CR> in the example.
- Use a smaller line range to preserve headings.
- Use :sort n when numeric ordering is needed instead.