Multi-file search-next and scroll

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

Multi-file search-next and scroll

Eric Arnold

I just created a set of scripts and mappings to search, search_next, and
scroll through a list of files without having the user deal with the
file/arg list, i.e. "n" and "^D", etc. automatically move the user into the
next file.  I didn't find this functionality in Vim (i.e / and then *
in "less").  Am I re-inventing?


Reply | Threaded
Open this post in threaded view
|

Re: Multi-file search-next and scroll

A.J.Mechelynck
Eric Arnold wrote:
> I just created a set of scripts and mappings to search, search_next, and
> scroll through a list of files without having the user deal with the
> file/arg list, i.e. "n" and "^D", etc. automatically move the user into the
> next file.  I didn't find this functionality in Vim (i.e / and then *
> in "less").  Am I re-inventing?

In Vim 7, we can do, for instance,

        :vimgrep /\c<div\>/g *.htm *.html

which will search all HTML files in the current directory for <DIV> tags
(case-insensitive). The first occurrence will be shown with the cursor
on it; then

        :cn

goes to the next match (in the same file or a different one); and

        :cN

goes from one match to the previous one (in the same file or not).

Vim 6 and lower can do it too, but it must use an external program, with
the 'grepprg' option and the ":grep" command.

Similarly, if we have a pattern (with / bounds and flags if necessary)
in a variable named g:pattern and a space-separated list of files in a
String variable named g:list (with spaces [if any] backslash-escaped in
file names) we van do

        :exe "vimgrep" g:pattern g:list

See ":help quickfix.txt"


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

Re: Multi-file search-next and scroll

Eric Arnold
In reply to this post by Eric Arnold
Ya, quickfix is good, but is better for searching far and wide or deep with
lots of matches.  But what I'm try to do is allow the user edit a group of
files as if they were one, or close anyway.  If you are happily editing along
(i.e. edit, tagjump, edit, think of the next place to go, then rinse and
repeat), and then you have to do something special like sidetrack to grep and
quickfix (when grep/QF would return only a single match in a file several files
away) instead of "/" and "N", it destroys the illusion of oneness :-)

So, it sounds like it might be worth while to post it when/if I get it working
nicely.  Right now it's specialized to a particular set of files and needs to
be generalized, in addition to

P.S.  Is the best way of finding a script with a particular functionality the
search page on Source Forge/Vim Home?



--- "A. J. Mechelynck" <[hidden email]> wrote:

> Eric Arnold wrote:
> > I just created a set of scripts and mappings to search, search_next, and
> > scroll through a list of files without having the user deal with the
> > file/arg list, i.e. "n" and "^D", etc. automatically move the user into the
> > next file.  I didn't find this functionality in Vim (i.e / and then *
> > in "less").  Am I re-inventing?
>
> In Vim 7, we can do, for instance,
>
> :vimgrep /\c<div\>/g *.htm *.html
>
> which will search all HTML files in the current directory for <DIV> tags
> (case-insensitive). The first occurrence will be shown with the cursor
> on it; then
>
> :cn
>
> goes to the next match (in the same file or a different one); and
>
> :cN
>
> goes from one match to the previous one (in the same file or not).
>
> Vim 6 and lower can do it too, but it must use an external program, with
> the 'grepprg' option and the ":grep" command.
>
> Similarly, if we have a pattern (with / bounds and flags if necessary)
> in a variable named g:pattern and a space-separated list of files in a
> String variable named g:list (with spaces [if any] backslash-escaped in
> file names) we van do
>
> :exe "vimgrep" g:pattern g:list
>
> See ":help quickfix.txt"
>
>
> Best regards,
> Tony.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Multi-file search-next and scroll

A.J.Mechelynck
Eric Arnold wrote:
[...]
> P.S.  Is the best way of finding a script with a particular functionality the
> search page on Source Forge/Vim Home?
[...]

The best one known to me anyway.


Best regards,
Tony.