On Fri, Feb 4, 2011 at 6:17 PM, Marc Weber <[email protected]> wrote:

> Excerpts from David Lam's message of Fri Feb 04 23:57:04 +0000 2011:
> > you probably want...   vimgrep pattern file_folder/*.c
> >
> > maybe more useful is going through all sub folders recursively...
> > vimgrep pattern file_folder/**/*.c
>
> If I got you correct you want to create a file like this:
>
> == directories-to-search ==
> project1/
> project2/
> project3/
>
> Then you want Vim to read the lines and grep each folder which was
> listed in it?
>
>  let name = input("the word to grep for :")
>  for folder in readfile("directories-to-search")
>    exec 'vimgrepadd '.fnameescape(folder)..' '.fnameescape(folder).'/**/*'
>  endfor
>
> Put it into a function and map that.
>
> Marc Weber
>
> Thanks Marc and David.

The final solution for me:
I put all the directories into a file called sdir.txt, put this file under
the same folder of the source files,
add this function to vimrc file:

""Find the string user input in different folder
""put the search directories in sdir.txt file,
""under the same dir of the source code

nmap <F1>  :call <SID>Searchwordgl()<cr>

function s:Searchwordgl()

  let searchstring = expand("<cword>")      "search string under the cursor

  let searchdirlist = readfile('sdir.txt','',6)      "read directories into
list
  let searchdir = join(searchdirlist)             " join the list into
string

  if searchstring != ""
    execute "vimgrep " searchstring searchdir
  endif

endfunction

-- 
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 via email to