How to sort text using vim

In the newer vim 7 there is a :sort command. This is much easier to remember and works cross platform than using the external command.

If you have an older version of vim on unix you can use an external sort command. Move the cursor to the first line to be sorted.
ma Mark the first line as mark a.
Move to the bottom of the text to be sorted.
!`asort The ! command tells Vim to run the text through UNIX command. The `a tell the editor that the text to be worked on starts at the current line and ends at mark a. The command that the text is to go through is sort.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: