How to sort numeric and literal columns in Vim

sorting, vim

Solution

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

Problem

Using Vim 6.0. Say I'm editing this file: ``` sdfsdg dfgdfg 34 12 2 4 45 1 34 5 ``` How do I sort the second column?

Original source