Wednesday, June 29, 2011

Re: Fold the output of grep

On Jun 29, 9:46 pm, howard Schwartz <howard...@gmail.com> wrote:
> Here's what I would like to do: Using gnu grep (or similar one), search files
> for some string, STRING, with the output including a context line before and
> after each line found. That would look like:
>
> filename:21: This is a context line
> filename:22: This line contains STRING
> filename:23: This is another context line
>
> I save this output in a file and then open the file with vim. I want vim
> to fold the context lines, so I see only lines containing STRING. Now I can
> look at the target lines to find the one I am interested in, and if I need
> some context to help me, I can unfold the context lines. I should be able to
> use gF to open any file and line I want to go to.
>
> For that that would be the perfect grep. I want it in particular, to search
> my zillions of saved emails for a message containing a pattern.
>

http://vim.wikia.com/wiki/Fold_regular_expression

> It would be nice if I could unfold both the context line before and after the
> target line, with one operation. But I do not know how to do that. Is there a
> way to make the visible linei of a fold, be the line in the middle of that
> fold?
>

With the script at the above link, there are two levels of fold, with
more context at each level. You can use zr/zm to increase/decrease the
fold level, but this affects the entire buffer.

> A quickfix list would do some of this, but I do not think such a list can
> display output results that include context lines. I tried it once using gnu
> grep as the external grep - but it did not seem to work.
>
> Suggestions on how to accomplish this?

--
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: