Re: How to: display only the lines that have a matching pattern and fold /hide others.

2007-02-21 Thread Jean-Rene David
* Muddassirali Mirzani [2007.02.21 07:30]:
>  Is there a way to display only the lines that match
>  a search pattern and hide/fold others.

The foldutil plugin makes that very easy. I use it
quite a bit.

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

-- 
JR


Re: How to: display only the lines that have a matching pattern and fold /hide others.

2007-02-21 Thread Tim Chase
>  Is there a way to display only the lines that match
>  a search pattern and hide/fold others.
>  Any help appreciated. 

There are a number of ways to get the effect you are looking for.
 One might be:

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


which will actually use folding to fold away any adjacent lines
that don't match 'pattern'.  However, if there aren't adjacent
lines, the folding doesn't always show up (you see it in the
fold-column if you have that showing, but it's not usually
visible otherwise).  You can tweak the 'foldminlines' setting and
bump this back to 0 to get some visual indicator that a single
line is folded:

:set foldminlines=0

You could also do something like

:match Comment /pattern/

which will make every line matching /pattern/ appear as if it's
commented out.  You can even take this a step further and make a
highlighting target like

hi Invisible termbg=black termfg=black

and then use "Invisible" rather than "Comment".

This doesn't actually fold away the lines, but it just makes your
non-"hidden" lines pop out visually.

Another idea would be just to exploit the powerful undo abilities
of Vim and simply

:g/pattern/d

to delete the lines you don't want to see, and then just use "u"
to undo it.  (or save beforehand, delete the lines, and then
re-edit the file with ":e!")

Just a few ideas depending on the sort of behavior you want.

HTH,

-tim






Re: How to: display only the lines that have a matching pattern and fold /hide others.

2007-02-21 Thread Yakov Lerner

On 2/21/07, Jeenu V <[EMAIL PROTECTED]> wrote:

If you pattern happens to be word, then you can place cursor over the
word and then press [I or [i. See also ":h [I"

On 2/21/07, Muddassirali Mirzani <[EMAIL PROTECTED]> wrote:
>  Is there a way to display only the lines that match
>  a search pattern and hide/fold others.
>  Any help appreciated.
>  Thanks ..


Hello,
This is what I use:

fu! ToggleFoldByCurrentSearchPattern()
  if !&foldenable
set foldenable
set foldmethod=expr
set foldexpr=getline(v:lnum)!~@/
:normal zM
set foldmethod=manual
echo "zR to open all folds; zo top open 1 fold; zc to close 1 fold"
  else
 set nofoldenable
  endif
endfu
:nmap  :call ToggleFoldByCurrentSearchPattern()

Yakov


Re: How to: display only the lines that have a matching pattern and fold /hide others.

2007-02-21 Thread Jeenu V

If you pattern happens to be word, then you can place cursor over the
word and then press [I or [i. See also ":h [I"

On 2/21/07, Muddassirali Mirzani <[EMAIL PROTECTED]> wrote:

 Is there a way to display only the lines that match
 a search pattern and hide/fold others.
 Any help appreciated.
 Thanks ..






Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367



How to: display only the lines that have a matching pattern and fold /hide others.

2007-02-21 Thread Muddassirali Mirzani
 Is there a way to display only the lines that match
 a search pattern and hide/fold others.
 Any help appreciated. 
 Thanks ..
  



 

Food fight? Enjoy some healthy debate 
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367