Folding away based on a seach

2007-01-11 Thread Samuel Wright

HI All,

I have a todo list of single line entries.
I'd like to fold everything away apart from a custom seach, say

:customsearch urgent

would fold away all lines that did not contain urgent.

Has this been done already in some way?

If not, can I search, get the line numbers with results on, and do the
math to fold away everything else?

Ie, if lines 3 and 8 contain the term,
mark 1-2, fold
mark 4-7 fold
mark 9-end fold

Thanks for your help
S


Re: Folding away based on a seach

2007-01-11 Thread Tim Chase

would fold away all lines that did not contain urgent.

Has this been done already in some way?

If not, can I search, get the line numbers with results on, and do the
math to fold away everything else?


:set foldmethod=expr
:set foldexpr=getline(v:lnum)!~'urgent'


should do what you describe.  You can learn more at

:help foldmethod
:he foldexpr
:he fold-expr

(this abuses the fact that boolean-true is non-zero and 
boolean-false is zero which can be used as fold-levels)


Gotta love the succinctness of vim. :)

-tim





Re: Folding away based on a seach

2007-01-11 Thread Noah Spurrier
 HI All,

 I have a todo list of single line entries.
 I'd like to fold everything away apart from a custom seach, say

 :customsearch urgent

 would fold away all lines that did not contain urgent.

 Has this been done already in some way?

 If not, can I search, get the line numbers with results on, and do the
 math to fold away everything else?

 Ie, if lines 3 and 8 contain the term,
 mark 1-2, fold
 mark 4-7 fold
 mark 9-end fold

 Thanks for your help
 S


I have this map setup in my .vimrc, so \z will hide all lines that
don't contain the current search pattern.
map silentleaderz :set foldexpr=getline(v:lnum)!~@/ foldlevel=0
foldcolumn=0 foldmethod=exprCR

So in your case, you would search for URGENT in the usual way
   /URGENT
then type \z to hide every line that doesn't have URGENT
   \z

It comes in handy quite often. This is about the only way that
I ever use folding in fact.

Yours,
Noah




Re: Folding away based on a seach

2007-01-11 Thread Jean-Rene David
* Samuel Wright [2007.01.11 06:15]:
 I have a todo list of single line entries.
 I'd like to fold everything away apart from a custom seach, say
 
 :customsearch urgent
 
 would fold away all lines that did not contain urgent.
 
 Has this been done already in some way?

Yes.

http://www.vim.org/scripts/script.php?script_id=158

-- 
JR