How to sort numeric and literal columns in Vim

Solution 1:

If you have decent shell available, select your numbers and run the command

:'<,'>!sort -n -k 2

If you gonna type this in visual mode, after typing the colon, markers '<,'> will appead automatically, and you'll only have to type the rest of it.

This type of commands (:[motion]!) is called filtering. You can learn more by consulting vim's help:

:h filter

Solution 2:

Sort all lines on second column N by using Vim sort command, e.g.

:sort /.*\%2v/ 

Reference: vimtips.txt

Solution 3:

For vim7 I would go for:

:sort n /.*\s/

This will sort numbers ignoring text matched by given regexp. In your case it is second column.