Thursday, December 2, 2010

Re: How to sort folding titles alphabetically?

Firstly, your foldexpr gave my vim indigestion, causing it to hang CPU
bound when I attempted the following. I suggest temporarily setting
fdm=manual if you try it.

If you can write a regex that matches the lines with your titles, you
could

:v/regex/s/$/xyzzy "mark the ends of non-title lines
:g/xyzzy/-j! "join non-title lines with the one before it
:sort
:%s/xyzzy/\r/g "separate the lines out again
:g/regex/-m . "move blank line to right place

You might want to adjust the sort to suit your title lines; f.ex. I
tested on eval.txt and its titles have a number, so I used :sort /\d\+
\. /

Beware, though, vim doesn't like really long lines. When I tested on
eval.txt gvim's memory as reported by my system monitor jumped to 500
MB, making my system swap furiously for a while. If your file has
long blocks, longer than a few thousand lines vim might not cope.
Maybe joining with the line before could be done in a way that isn't
O(n^2), say joining them in pairs.

If vim doesn't suit, you could use the same decorate, join, sort,
split method with sed and sort I'm sure.

Regards, John

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment