Edit file in filtered view

2 views
Skip to first unread message

Pär Adeen

unread,
Dec 1, 2008, 3:48:59 PM12/1/08
to vim...@googlegroups.com

This is something that partly is provided by vim by folding. But I don't want the folding texts...

What I want is to watch a file in two views where the second one is a filtered view of the first one.

Can anyone please help me. I'm not a very advanced user

 

Q. I would like to have a dual view of my file with many thousand lines.

A. I could do this with a vertical split.

 

Q. Then I would like to two windows to be synchronized.

A. I could do this with the :scrollbind command

 

So far everything is good... But then:

 

Q. I want to filter the view to only show text matching my regex

A. There's a VIM-tip's for that:

:set fold

:set foldexpr=getline(v:lnum)!~@/
:nnoremap <F8> :set foldmethod=expr<CR><Bar>zM

 

The problem is that I cant get rid of the text: "+--27 lines: xxx-----------------"

I would like a list of all lines containing my regex and nothing else. The output I would like is similar to the output generated by this command:

:g!/MyRegEx/d

but I don't want to delete the text since I want to edit the complete file (but in a filtered view)

 

The second problem I get is that I want to :scrollbind to completely sync the lines between the current cursor line in my filtered window with the line i my unfiltered windows so that I could see the surrounding text

 

Example:

 

Windows 1 (original)
========   
1 Line 1   
2 Line 2   
3 Line 3 foo
4 Line 4   
5 Line 5   
6 Line 6 foo
7 Line 7

 

Windows 2 (filtered on /foo/)
========
3 Line 3 foo
6 Line 6 foo



Beställ bläck före 19 för leverans nästa vardag inkClub

Michael Phillips

unread,
Dec 1, 2008, 10:05:10 PM12/1/08
to vim...@googlegroups.com
This is an idea, so I do not know how well it will work. Have you try
to use syntax highlighting? Make the text you do not want the same
color as the background.

pade

unread,
Dec 2, 2008, 1:50:25 AM12/2/08
to vim_use
Thanks, But this will not help since the file could be almost 1MB and
there could be many lines between the hits.
I don't think this use-case is unique. To filter out irrelevant data
and only work with the relevant data. That's what many script-
languages like perl etc. was developed for...

If vim can't do this, we will probably build a special editor for
this. But hey... I'm the only vim-user at the company and this is a
chance to get other to use/like vim as well.
> > Beställ bläck före 19 för leverans nästa vardag inkClub- Dölj citerad text -
>
> - Visa citerad text -

pade

unread,
Dec 2, 2008, 1:55:45 AM12/2/08
to vim_use
Hi again. The example should be:

Windows 1 (original)========
1 Line 1
2 Line 2
3 Line 3 foo
4 Line 4
5 Line 5
6 Line 6 foo
7 Line 7


Windows 2 (filtered on /foo/)========
3 Line 3 foo
6 Line 6 foo

BR

pade

unread,
Dec 2, 2008, 7:04:33 PM12/2/08
to vim_use
Ok, Almost solved. With the following commands I can fold on the
active search expression:
:vsplit
:set foldmethod=expr
:set foldexpr=getline(v:lnum)!~@/

Then with the following command I could get rid of the annoying text
at each folding. Not as good as removing the line, but good enough :-
(
:set foldtext=v:folddashes.substitute(getline(v:foldstart),'.*','','')

Then I must make sure that every tiny thing is folded
:set foldminlines=0

I then use the following command to bind the two windows:
:set scrollbind

Whats left (besides removing the folding line) is to bind the not
filtered window to my cursors current line in my filtered window. The
scrollbind is not good enough here since it syncs on the whole window
rather than on my cursor.





On 1 Dec, 21:48, Pär Adeen <par_ad...@hotmail.com> wrote:
> This is something that partly is provided by vim by folding. But I don't want the folding texts...
> What I want is to watch a file in two views where the second one is a filtered view of the first one.
> Can anyone please help me. I'm not a very advanced user
>
> Q. I would like to have a dual view of my file with many thousand lines.
> A. I could do this with a vertical split.
>
> Q. Then I would like to two windows to be synchronized.
> A. I could do this with the :scrollbind command
>
> So far everything is good... But then:
>
> Q. I want to filter the view to only show text matching my regex
> A. There's a VIM-tip's for that:
> :set fold
> :set foldexpr=getline(v:lnum)!~@/:nnoremap <F8> :set foldmethod=expr<CR><Bar>zM
>
> The problem is that I cant get rid of the text: "+--27 lines: xxx-----------------"
> I would like a list of all lines containing my regex and nothing else. The output I would like is similar to the output generated by this command:
> :g!/MyRegEx/d
> but I don't want to delete the text since I want to edit the complete file (but in a filtered view)
>
> The second problem I get is that I want to :scrollbind to completely sync the lines between the current cursor line in my filtered window with the line i my unfiltered windows so that I could see the surrounding text
>
> Example:
>
> Windows 1 (original)========    1 Line 1    2 Line 2    3 Line 3 foo4 Line 4    5 Line 5    6 Line 6 foo7 Line 7
>
> Windows 2 (filtered on /foo/)========3 Line 3 foo6 Line 6 foo
>
> _________________________________________________________________
> Var sommaren för kort? Här hittar du solen!http://resor.se.msn.com/

John Beckett

unread,
Dec 2, 2008, 8:26:05 PM12/2/08
to vim...@googlegroups.com
pade wrote:
> Whats left (besides removing the folding line) is to bind the
> not filtered window to my cursors current line in my filtered
> window. The scrollbind is not good enough here since it syncs
> on the whole window rather than on my cursor.

I'm not recommending this, but as a matter of interest the "Conceal" patch includes
the 'cursorbind' option.
http://groups.google.com/group/vim_dev/web/vim-patches

John

Marc Weber

unread,
Dec 2, 2008, 9:03:29 PM12/2/08
to vim...@googlegroups.com
On Mon, Dec 01, 2008 at 09:48:59PM +0100, Pär Adeen wrote:
> This is something that partly is provided by vim by folding. But I don't
> want the folding texts...
>
> What I want is to watch a file in two views where the second one is a
> filtered view of the first one.
>
> Can anyone please help me. I'm not a very advanced user
First of all I think you've found the best solution for your use case
Maybe http://www.vim.org/scripts/script.php?script_id=2014
could be tweaked to match your use case (however I doubt it works well
with that big files)
Another solution is using egrep and the quickfix buffer or the like.
But windows will not be synchronized.

Marc

Tony Mechelynck

unread,
Dec 2, 2008, 11:44:09 PM12/2/08
to vim...@googlegroups.com
On 02/12/08 07:50, pade wrote:
> Thanks, But this will not help since the file could be almost 1MB and
> there could be many lines between the hits.
> I don't think this use-case is unique. To filter out irrelevant data
> and only work with the relevant data. That's what many script-
> languages like perl etc. was developed for...
>
> If vim can't do this, we will probably build a special editor for
> this. But hey... I'm the only vim-user at the company and this is a
> chance to get other to use/like vim as well.
[...]

You may want Vim to display the relevant lines as a message rather than
as an edit buffer: see ":help :g"

For instance, to display only the lines contining the words "foo" and
"bar" in that order (each as a word, without quotes, and with anything
between them), you might use

:g/\<foo\>.*\<bar\>/p

(From quickfix.txt lines 614-615:
[Unix trivia: The name for the Unix "grep" command comes from ":g/re/p",
where
"re" stands for Regular Expression.]
)

Best regards,
Tony.
--
"When I get real bored, I like to drive downtown and get a great
parking spot, then sit in my car and count how many people ask me if
I'm leaving."
-- Steven Wright

Tony Mechelynck

unread,
Dec 2, 2008, 11:49:12 PM12/2/08
to vim...@googlegroups.com
On 03/12/08 05:44, Tony Mechelynck wrote:
> On 02/12/08 07:50, pade wrote:
>> Thanks, But this will not help since the file could be almost 1MB and
>> there could be many lines between the hits.
>> I don't think this use-case is unique. To filter out irrelevant data
>> and only work with the relevant data. That's what many script-
>> languages like perl etc. was developed for...
>>
>> If vim can't do this, we will probably build a special editor for
>> this. But hey... I'm the only vim-user at the company and this is a
>> chance to get other to use/like vim as well.
> [...]
>
> You may want Vim to display the relevant lines as a message rather than
> as an edit buffer: see ":help :g"
>
> For instance, to display only the lines contining the words "foo" and
> "bar" in that order (each as a word, without quotes, and with anything
> between them), you might use
>
> :g/\<foo\>.*\<bar\>/p
>
> (From quickfix.txt lines 614-615:
> [Unix trivia: The name for the Unix "grep" command comes from ":g/re/p",
> where
> "re" stands for Regular Expression.]
> )
>

P.S. See also ":help :redir" about capturing, for instance, the output
of ":g/something/p".

>
>
> Best regards,
> Tony.
--
The pitcher wound up and he flang the ball at the batter. The batter
swang and missed. The pitcher flang the ball again and this time the
batter connected. He hit a high fly right to the center fielder. The
center fielder was all set to catch the ball, but at the last minute
his eyes were blound by the sun and he dropped it.
-- Dizzy Dean

Reply all
Reply to author
Forward
0 new messages