Hi,

Vim Visual wrote:
> 
> I have a text file like
> 
> Mr Bla Blo
> Ms Ble Blu
> Dr Bli Blu
> etc
> 
> and I would like to sort the file alphabetically after the surname
> (3rd column). How can I do that? I know how to sort it after the first
> one (visual + !sort)

with VIM 7 you can sort inside VIM:

  :%sort /^\S\+\s\+\S\+\s\+/

tells VIM to skip the first two words in every line and to sort on
whatever follows.

If the third column is always the last column another way would be to

  :%sort /\<\S\+\>$/ r

The "r" flag tells VIM to sort based on the matched text, which is the
last word in this case. This would also work around your problem with
initials you mentioned in your second mail.

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

Reply via email to