Howto :vimgrep over :argdo, please? :-)

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

Howto :vimgrep over :argdo, please? :-)

François Pinard
Hi, gang.  Could someone enlighten me?

I much like the new `:vim' command under Vim7, but notice that I
frequently need to use it over the list of argument files (those files
`:argdo` is operating upon), and find it a bit cumbersome having to
repeat the argument list over and over on the various `:vim' commands.

Is there a way of, somehow, combining these commands?  Or am I missing
something evident?

             Thanks in advance for insights you might provide.

--
Fran?ois Pinard   http://pinard.progiciels-bpi.ca
Reply | Threaded
Open this post in threaded view
|

Re: Howto :vimgrep over :argdo, please? :-)

A.J.Mechelynck
----- Original Message -----
From: "Fran?ois Pinard" <[hidden email]>
To: "Vim users" <[hidden email]>
Sent: Tuesday, August 30, 2005 5:53 PM
Subject: Howto :vimgrep over :argdo, please? :-)


> Hi, gang.  Could someone enlighten me?
>
> I much like the new `:vim' command under Vim7, but notice that I
> frequently need to use it over the list of argument files (those files
> `:argdo` is operating upon), and find it a bit cumbersome having to
> repeat the argument list over and over on the various `:vim' commands.
>
> Is there a way of, somehow, combining these commands?  Or am I missing
> something evident?
>
>             Thanks in advance for insights you might provide.
>
> --
> Fran?ois Pinard   http://pinard.progiciels-bpi.ca

":vimgrep" accepts a filename (with wildcards), and the wildcards are more
powreful than Windows. For instance,

    :vimgrep    /\<J&eacute;rusalem\>/g    ../**/*.htm

searches for the word J?rusalem (with ? replaced by the equivalent entity)
in all *.HTM files in the parent of the current directory and all its
subdirectories.

see
    :help :vimgrep
    :help starstar  " where it says it goes up do 30 directories deep
    :help starstar-wildcard  " where it says it goes up to 100 directories
deep


Note: I have found the following handy:

    :map <F2> :cn<CR>
    :map <S-F2> :cN<CR>
    :imap <F2> <C-O>:cn<CR>
    :imap <S-F2> <C-O>:cN<CR>


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: Howto :vimgrep over :argdo, please? :-)

Mikołaj Machowski
In reply to this post by François Pinard
Dnia wtorek, 30 sierpnia 2005 17:53, Fran?ois Pinard napisa?:

> Hi, gang.  Could someone enlighten me?
>
> I much like the new `:vim' command under Vim7, but notice that I
> frequently need to use it over the list of argument files (those files
> `:argdo` is operating upon), and find it a bit cumbersome having to
> repeat the argument list over and over on the various `:vim' commands.
>
> Is there a way of, somehow, combining these commands?  Or am I missing
> something evident?
>
>              Thanks in advance for insights you might provide.

According to docs something like::

    :argdo vimgrepadd! pattern %

Should work. Bot does not :(

Another use is::

    :argdo vimgrep pattern %

Downsides:

1. Completely don't understand why it adds random files to the args list
2. There is no single error list but separate lists for each file.
   Between error lists you can move with :colder, :cnewer.

However, current state looks more like a bug (or not fully implemented).

m.

Reply | Threaded
Open this post in threaded view
|

Re: Howto :vimgrep over :argdo, please? :-)

Bill McCarthy
In reply to this post by François Pinard
On Tue 30-Aug-05 10:53am -0500, François Pinard wrote:

> I much like the new `:vim' command under Vim7, but notice that I
> frequently need to use it over the list of argument files (those files
> `:argdo` is operating upon), and find it a bit cumbersome having to
> repeat the argument list over and over on the various `:vim' commands.
>
> Is there a way of, somehow, combining these commands?  Or am I missing
> something evident?

Since the argdo doesn't appear to do it, you could try
something like this:

=======================================================
fu! s:argvim( arg )
    let s:a = ""
    let s:i = 0
    while s:i < argc()
        let s:a = s:a . ' ' . escape(argv(s:i), ' \')
        let s:i = s:i + 1
    endwhile
    exe "vim " . a:arg . s:a
endf

com! -nargs=1 Argvim call <SID>argvim( "<args>" )
=======================================================

You could then search the arg files for "fopen" with:

:Argvim /fopen/

--
Best regards,
Bill


Reply | Threaded
Open this post in threaded view
|

Re: Howto :vimgrep over :argdo, please? :-)

Bram Moolenaar
In reply to this post by Mikołaj Machowski

Mikolaj Machowski wrote:

> Dnia wtorek, 30 sierpnia 2005 17:53, Fran?ois Pinard napisa?:
> > Hi, gang.  Could someone enlighten me?
> >
> > I much like the new `:vim' command under Vim7, but notice that I
> > frequently need to use it over the list of argument files (those files
> > `:argdo` is operating upon), and find it a bit cumbersome having to
> > repeat the argument list over and over on the various `:vim' commands.
> >
> > Is there a way of, somehow, combining these commands?  Or am I missing
> > something evident?
> >
> >              Thanks in advance for insights you might provide.
>
> According to docs something like::
>
>     :argdo vimgrepadd! pattern %
>
> Should work. Bot does not :(

It works fine for me.  What is the problem you ran into?

--
In a world without fences, who needs Gates and Windows?

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: Howto :vimgrep over :argdo, please? :-)

Mikołaj Machowski
Dnia ?roda, 31 sierpnia 2005 10:44, Bram Moolenaar napisa?:

> Mikolaj Machowski wrote:
> > Dnia wtorek, 30 sierpnia 2005 17:53, Fran�ois Pinard napisa?:
> > > Hi, gang.  Could someone enlighten me?
> > >
> > > I much like the new `:vim' command under Vim7, but notice that I
> > > frequently need to use it over the list of argument files (those
> > > files `:argdo` is operating upon), and find it a bit cumbersome
> > > having to repeat the argument list over and over on the various
> > > `:vim' commands.
> > >
> > > Is there a way of, somehow, combining these commands?  Or am I
> > > missing something evident?
> > >
> > >              Thanks in advance for insights you might provide.
> >
> > According to docs something like::
> >     :argdo vimgrepadd! pattern %
> >
> > Should work. Bot does not :(
>
> It works fine for me.  What is the problem you ran into?

Open bunch of tex files in directory with::

    vim *.tex

Then try::

    :clist                (error list is empty)
    :argdo vimgrepadd! attri %

In some of those files "attri" string is present, in some not.
In result I get list in form::

    attrib.tex|31 col 14| \newcommand{\attribution}[1]
{\raggedleft\textit{#1}}
    attrib.tex|51 col 3| \attribution{-- Anne Elk (Miss)
    attrib.tex|31 col 14| \newcommand{\attribution}[1]
{\raggedleft\textit{#1}}
    attrib.tex|51 col 3| \attribution{-- Anne Elk (Miss)
    attrib.tex|31 col 14| \newcommand{\attribution}[1]
{\raggedleft\textit{#1}}
    attrib.tex|51 col 3| \attribution{-- Anne Elk (Miss)

With "old style" command::

    argdo grepadd! attri %

I am getting (list of errors was empty)::

    attrib.tex|31| \newcommand{\attribution}[1]{\raggedleft\textit{#1}}
    attrib.tex|51| \attribution{-- Anne Elk (Miss)
    attrib.tex|31| \newcommand{\attribution}[1]{\raggedleft\textit{#1}}
    attrib.tex|51| \attribution{-- Anne Elk (Miss)
    attrib.tex|31| \newcommand{\attribution}[1]{\raggedleft\textit{#1}}
    attrib.tex|51| \attribution{-- Anne Elk (Miss)
    quality.tex|85| redistribute, reattribute, sell, buy, rent, lease,
    quality.tex|295| about credits but just for ensuring that the class
attribute
    quality.tex|85| redistribute, reattribute, sell, buy, rent, lease,
    quality.tex|295| about credits but just for ensuring that the class
attribute
    item.tex|31| \newcommand{\attribution}[1]{\raggedleft\textit{#1}}

'grepprg' is default "grep -n $* /dev/null".

Doing grep (2.5.1) from command line::

    :r!grep -n attri *.tex
   
    attrib.tex:31:\newcommand{\attribution}[1]{\raggedleft\textit{#1}}
    attrib.tex:51: \attribution{-- Anne Elk (Miss)
    item.tex:31:\newcommand{\attribution}[1]{\raggedleft\textit{#1}}
    quality.tex:85: redistribute, reattribute, sell, buy, rent, lease,
    quality.tex:295: about credits but just for ensuring that the class
attribute
    qual.tex:84: redistribute, reattribute, sell, buy, rent, lease,
    qual.tex:290: about credits but just for ensuring that the class
attribute
    vst.tex:31:\newcommand{\attribution}[1]{\raggedleft\textit{#1}}
    vst.tex:1572:\hypertarget{lattribution}{}
    vst.tex:1590: \attribution{-- John Smith, Esq.

m.

Reply | Threaded
Open this post in threaded view
|

Re: Howto :vimgrep over :argdo, please? :-)

Bram Moolenaar

Mikolaj Machowski wrote:

> Dnia ?roda, 31 sierpnia 2005 10:44, Bram Moolenaar napisa?:
> > Mikolaj Machowski wrote:
> > > Dnia wtorek, 30 sierpnia 2005 17:53, François Pinard napisa?:
> > > > Hi, gang.  Could someone enlighten me?
> > > >
> > > > I much like the new `:vim' command under Vim7, but notice that I
> > > > frequently need to use it over the list of argument files (those
> > > > files `:argdo` is operating upon), and find it a bit cumbersome
> > > > having to repeat the argument list over and over on the various
> > > > `:vim' commands.
> > > >
> > > > Is there a way of, somehow, combining these commands?  Or am I
> > > > missing something evident?
> > > >
> > > >              Thanks in advance for insights you might provide.
> > >
> > > According to docs something like::
> > >     :argdo vimgrepadd! pattern %
> > >
> > > Should work. Bot does not :(
> >
> > It works fine for me.  What is the problem you ran into?
>
> Open bunch of tex files in directory with::
>
>     vim *.tex
>
> Then try::
>
>     :clist                (error list is empty)
>     :argdo vimgrepadd! attri %
>
> In some of those files "attri" string is present, in some not.
> In result I get list in form::

That is not sufficient to reproduce the problem.  You don't even say
what the problem is.  I guess you only get matches in one file, three
times.  Perhaps you have autocommands that get in the way?  Try setting
'verbose' to find out what happens.  Or start with "vim -u NONE".

--
hundred-and-one symptoms of being an internet addict:
135. You cut classes or miss work so you can stay home and browse the web.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: Howto :vimgrep over :argdo, please? :-)

Mikołaj Machowski
> That is not sufficient to reproduce the problem.  You don't even say
> what the problem is.  I guess you only get matches in one file, three
> times.  Perhaps you have autocommands that get in the way?  Try setting
> 'verbose' to find out what happens.  Or start with "vim -u NONE".

NONE showed where problem is.

m.