Wikia

Vim Tips Wiki

Search through files

Talk0
1,613pages on
this wiki

Redirected from VimTip961

Tip 961 Printable Monobook Previous Next

created July 22, 2005 · complexity intermediate · author Bertram Scharpf · version 6.0


When searching all your source files where you left a /TODO/ or where you had version conflicts />>>>/, you may quickly step through all files using a mapping like:

nmap <F3> :silent exec "while !search( @/, \"W\") \| bnext \| 0 \| endwhile"<CR>

This automatically goes to the next file if the pattern doesn't occur in the current.

CommentsEdit

You can use BufGrep function. It greps for the relevant search string in all the opened buffers- the search result is available in a quick fox window.


Thanks for the Tip. I found that it didn't find the search pattern if the pattern was on the first line. The fix was start new buffer searches from the end of the file and wrap to the beginning. I also added a reverse search. Here's the updated mapping:

map <F3> :silent exec "let flags = \"W\" \| while !search( @/, flags) \| bnext \| $ \| let flags = \"w\" \| endwhile"<CR><CR>
map <S-F3> :silent exec "let flags = \"bW\" \| while !search( @/, flags) \| bprev \| 0 \| let flags = \"bw\" \| endwhile"<CR><CR>

I'm not entirely sure what this does - is it something that could be accomplished with :vimgrep or with :grep and a customized 'grepprg'? That would seem to me the better option.

See Find in files within Vim or :help :vimgrep, :help :grep, :help 'grepprg'.

--Fritzophrenic 18:22, 29 February 2008 (UTC)

Around Wikia's network

Random Wiki