Sort a set of lines

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Sort a set of lines

Giorgos Gaganis
Hello

I would like to sort a few lines in a buffer. I have looked at tip #588
but didn't help me much because I couldn't find the scripts it refers to.
Any help would be greatly appreciated.

Giorgos
Reply | Threaded
Open this post in threaded view
|

Re: Sort a set of lines

Chris Allen
On 02/11/05, Giorgos Gaganis <[hidden email]> wrote:
> I would like to sort a few lines in a buffer. I have looked at tip #588
> but didn't help me much because I couldn't find the scripts it refers to.
> Any help would be greatly appreciated.

You can do this, if you're on something Unix-like, with the :!
(filter) command.  Select your lines visually then type

    :!sort

If you want to give Vim7 a try you will find it comes with a
convenient :sort command.

HTH,
Chris Allen
Reply | Threaded
Open this post in threaded view
|

Re: Sort a set of lines

Luc Hermitte
In reply to this post by Giorgos Gaganis
Hello,

Giorgos Gaganis <[hidden email]> wrote:

> I would like to sort a few lines in a buffer. I have looked at tip #588
> but didn't help me much because I couldn't find the scripts it refers to.
> Any help would be greatly appreciated.

In system_utils (<http://hermitte.free.fr/vim/ressources/vimfiles/plugin/>), you
will found code, for :Sort, posted by Piet Delport on this list a few years ago.

Otherwise, on unix, a simple
  :'<,'>!sort sould do it.

--
Luc Hermitte
Reply | Threaded
Open this post in threaded view
|

Re: Sort a set of lines

Tim Chase-2
> Otherwise, on unix, a simple
>   :'<,'>!sort sould do it.

It will work on Windows/Dos as well, as there's a "sort" command there
as well...a tad more braindead, as it doesn't allow for all the nice
parameters you can pass to unix/gnu "sort", but for simple
alpha-sorting, it will suffice. If you want numerical sorting or sorting
by characters other than in the first position, you'll likely have to
install cygwin or one of the other ports of GNU tools to Win32.

-tim



Reply | Threaded
Open this post in threaded view
|

Re: Sort a set of lines

Charles E Campbell Jr
In reply to this post by Giorgos Gaganis
Giorgos Gaganis wrote:

> I would like to sort a few lines in a buffer. I have looked at tip
> #588 but didn't help me much because I couldn't find the scripts it
> refers to.
> Any help would be greatly appreciated.

Well, tip 588 refers to
http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs (see "Visual
Block Sorting" -- the topics are in alphabetical order).  The original
tip refers to my old website; you'd have to look at the "Additional
Notes" to see the new website, as we cannot edit our tips.  Wish we
could!  That said, the tip is referring to using visual block-based
based sorting (ie. use ctrl-v to select a rectangular region).  One can
sort lines based on just the text in a column, or sort just the contents
of the column (leaving the text outside of the column alone).

It seems you want to do some straight sorting of whole lines.   If you
have a decent external sort program, perhaps
    :[range]!sort
where you pick the range (ie.  :25,43!sort to sort lines 25-43
inclusive).  If you happen to be using vim 7.0, then the built-in sort
command is available:
    :[range]sort

Regards,
Chip Campbell