Is it possible to sort lines on line length?
Shortes firsts, longest last?
If so how do you do this?

This is a common use of the "decorate-sort-undecorate" pattern. You can do something like:

:%s/^/\=strlen(getline('.')).':'
:%sort n
:%s/^[^:]*:

In non-vim7 on a *nix platform, that second sort command becomes ":%!sort -n", as the internal sort command was added in Vim7, IIRC.

If you're running non-vim7 on a win32 platform where the external "sort" is less flexible, one would have to left-pad those numbers with zeros...changing the first line to something ugly like

:%s/^/\=matchstr('0000000'.strlen(getline('.')), '.\{8}$').':'

and then make the 2nd line

:%!sort

If you prefer it in reverse order (longest to shortest), the sort command(s) would become

[vim7]
:%sort nr
[*nix]
:%!sort -nr
[win32]
:%!sort /r

Just a few ideas.

-tim






Reply via email to