Saturday, February 16, 2013

Re: search string in open files

On 2013-02-16 12:28, Franco wrote:
> I use vim search (/) function quite a lot. Recently I started
> to use viewports; it is a real pleasure working with them, but they
> pose a problem to me.

I think by "viewports", you mean what Vim calls "windows" (splittings
of the current screen/application into what one might sensibly call
"viewports")

> I would like to be able to search for a word in /all open
> viewports/.
>
> So let say I have viewport a, b (active) and c opened, and the work
> 'toSearch' is somewhere in c, by typing (just saying):
>
> > /%toSearch
>
> I would like viewport c to scroll appropriately to show me such
> occurrence.

A couple ideas occur to me. You could do something like

:windo /%toSearch

which will enter each window/viewport, perform the search, then
continue to the next window and repeat. In this case, it happens to
be an Ex-mode search which will start at the next line (so if you
have a match after the cursor on the current line, it won't find
it). You can tweak that to get the more expected behavior by using

:windo norm /%toSearch

If you want to see *all* matches, you can use

:windo g/%toSearch/#
:windo g/%toSearch/

(the first one numbers the lines, the second one just prints them).
The problem with this is that, if you have multiple windows/viewports
open on the same file, it will report each one individually, giving
duplicate results.

Another possibility is to use :vimgrep which I just learned to use
within the last year and love the functionality. Especially on Win32
where the command-line grepping tools are far less useful than on
*nix systems. So you could do

:vimgrep /%toSearch/ pattern*.txt

then use

:cope
:cn
:cN

to navigate the results.

Lastly, to get what you actually describe would take a little
scripting. You'd have to optionally remember your current window
number (":help winnr()"), then iterate over your various windows,
and, if a match is found, stop iterating (optionally jumping back to
the initially-saved window).

-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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: