sorting in vim is simple.
a list of number like this:
3
30
423
21
3
9871
is easily sorted by typing “:sort” (every line in buffer) or “:%sort” (every line in buffer) or “1,5sort” (this last one only sorts lines 1 – 5)
resulting in:
21
3
3
30
423
9871
You can use the “-u” option while sorting to get rid of the duplicates, but you must also add the “!” (filter) option:
:%!sort -u
21
3
30
423
9871
The “%” means “all lines in buffer”
One last thing. You can use visual mode to highlight the bit that you want sorted and leave the rest alone.
CTRL-V and use the navigation keys h,j,k,l to select the text, then ESC and finally “:sort”




Recent Comments