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?
Sorting text in Vim is easy! Select the text, then press : , type sort , then hit enter! It'll sort the whole document by default, but you can enter a range too.
column happens to be the first column with a decimal number, note that you could use simply :sort n , as the help says: "With [n] ... sorting is done on the first decimal number in the line..." This doesn't apply to your case, but might to somebody elses.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With