Tuesday, July 1, 2008

Sorting a Column in Vim

I am also learning the Visual mode in Vim.
If you want to sort a column (usually selected)
in a file.

$ vim unsorted.txt
2
3
1
5
4

Go to the line, from where you want to start
the sort. Press Ctrl-v, now select the column
using arrow keys.
2
3
1
5
4

Now, press :sort in command mode. You will get
1
2
3
4
5