Command line: VIM

VIM: sorting and removing duplicates

There is one very useful command in VIM that allows to do both sorting of lines in current buffer and removing duplicated lines.

In order to do sorting type the following command:
:sort
gif1

In order to do both sorting and removing duplicates type the following command:
:sort u
gif2

Other useful options of :sort command:
:sort! – sort in reverse
:1,100sort – sort first 100 lines
:sort n – numeric sort (“20” goes before “100”)
:sort /{pattern}/ – sort based on pattern found in line (see an example here)
:help :sort – see help for sorting

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s