":windo g/pattern/q" peculiarity

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

":windo g/pattern/q" peculiarity

Tim Chase
Not sure if this is an old-version-of-vim thing, or if it's just
a peculiar interaction.  Scenario: I had a bunch of vim-windows
open on various files and wanted to close those that contained a
given pattern (in the example below, using "@" as my pattern to
close windows with email addresses in them), so I issued:

   :windo g/pattern/q

which did as I expected, but had the odd side effect of printing
misleading messages about additional/fewer lines:

   193 more lines
   E486: Pattern not found: @
   86 fewer lines
   16 fewer lines
   E486: Pattern not found: @

(the E486 is ignorable because those were the files that didn't
match the pattern).  No lines were actually added/removed.  The
"more"/"fewer" lines likely comes from Vim noting the number of
lines before the ":g" and comparing it to number of lines after
the ":g", and reporting the difference, but not noticing that the
file/buffer/window had changed in the process.

Looks like a minor bug or underdocumentation to me, though
certainly not grievous.

-tim


--
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
Reply | Threaded
Open this post in threaded view
|

Re: ":windo g/pattern/q" peculiarity

Jean-Rene David-2
* Tim Chase [2011.04.28 14:00]:
[...]

>   :windo g/pattern/q
>
> which did as I expected, but had the odd side effect of printing
> misleading messages about additional/fewer lines:
>
>   193 more lines
>   E486: Pattern not found: @
>   86 fewer lines
>   16 fewer lines
>   E486: Pattern not found: @

I can't reproduce this on terminal vim 7.3.143. I had two files open:

$ cat /tmp/foo
1+2
@11+12
$ cat /tmp/bar
barou

and used both '@' and '1' as patterns.

I get the E486 error but not the more/less lines messages.

[...]
> The "more"/"fewer" lines likely comes from Vim noting the number of
> lines before the ":g" and comparing it to number of lines after the
> ":g", and reporting the difference, but not noticing that the
> file/buffer/window had changed in the process.

I don't understand what you mean. I don't see how the number of lines
could have changed.

--
JR

--
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
Reply | Threaded
Open this post in threaded view
|

Re: ":windo g/pattern/q" peculiarity

Tim Chase
On 04/28/2011 01:15 PM, Jean-Rene David wrote:

> * Tim Chase [2011.04.28 14:00]:
> [...]
>>    :windo g/pattern/q
>>
>> which did as I expected, but had the odd side effect of printing
>> misleading messages about additional/fewer lines:
>>
>>    193 more lines
>>    E486: Pattern not found: @
>>    86 fewer lines
>>    16 fewer lines
>>    E486: Pattern not found: @
>
> I can't reproduce this on terminal vim 7.3.143. I had two files open:
>
> $ cat /tmp/foo
> 1+2
> @11+12
> $ cat /tmp/bar
> barou
>
> and used both '@' and '1' as patterns.
>
> I get the E486 error but not the more/less lines messages.

Because each of your files have the same number of lines, it
doesn't register a change.  For a full example:

  bash$ cd ~/tmp; mkdir moreless; cd moreless
  bash$ for i in 10 20 30 40 50; do seq $i > ${i}.txt ; done
  bash$ sed -i '5s/$/@/' 30.txt
  bash$ sed -i '10s/$/@/' 50.txt
  bash$ vim -o *.txt
  :windo g/@/q

produces (on the stock 7.2.445 that comes with Debian Squeeze)

   E486: Pattern not found: @
   E486: Pattern not found: @
   10 more lines
   E486: Pattern not found: @
   10 fewer lines

-tim


--
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
Reply | Threaded
Open this post in threaded view
|

Re: ":windo g/pattern/q" peculiarity

Jean-Rene David-2
* Tim Chase [2011.04.28 14:40]:
> Because each of your files have the same number of lines, it doesn't
> register a change.  For a full example:
>
>  bash$ cd ~/tmp; mkdir moreless; cd moreless
>  bash$ for i in 10 20 30 40 50; do seq $i > ${i}.txt ; done
>  bash$ sed -i '5s/$/@/' 30.txt
>  bash$ sed -i '10s/$/@/' 50.txt
>  bash$ vim -o *.txt
>  :windo g/@/q

Got it now.

The problem is that the :g command just subtracts the number of lines in
the buffer where it starts from the number of lines in the buffer where
it ends to produce that message.

Of course it assumes those two buffers are the same but it doesn't
*check* that it is so.

I have a small patch to fix that as soon as my registration on vim-dev
goes through...

--
JR

--
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
Reply | Threaded
Open this post in threaded view
|

Re: ":windo g/pattern/q" peculiarity

Tim Chase
On 04/28/2011 09:49 PM, Jean-Rene David wrote:

> * Tim Chase [2011.04.28 14:40]:
>> Because each of your files have the same number of lines, it doesn't
>> register a change.  For a full example:
>>
>>   bash$ cd ~/tmp; mkdir moreless; cd moreless
>>   bash$ for i in 10 20 30 40 50; do seq $i>  ${i}.txt ; done
>>   bash$ sed -i '5s/$/@/' 30.txt
>>   bash$ sed -i '10s/$/@/' 50.txt
>>   bash$ vim -o *.txt
>>   :windo g/@/q
>
> Got it now.
>
> The problem is that the :g command just subtracts the number of lines in
> the buffer where it starts from the number of lines in the buffer where
> it ends to produce that message.
>
> Of course it assumes those two buffers are the same but it doesn't
> *check* that it is so.

That's sorta what I figured, as I mentioned in my original post:

TKC> lines before the ":g" and comparing it to number of lines after
TKC> the ":g", and reporting the difference, but not noticing
that the
TKC> file/buffer/window had changed in the process.

Thanks for throwing together a patch.

-tim



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