On Thu, January 14, 2010 1:31 am, [email protected] wrote: > I create a project including many files which are spread over to > different directory. I have the file lists in one file and use the > file as the input for ctags and cscope to create the tags. I want to > know how to search a string only in the listed files in vim? This will > behave similar like many IDE to search the string in the project.
If you are in the window with your filelist, you can use vimgrep for searching in these files: :exe 'vimgrep /Pattern/gj ' . join(map(getline(1,'$'), 'escape(v:val, " ")')) This command executes the vimgrep command on the result of evaluating the expression join(map(getline(1,'$'), 'escape(v:val, " ")')). This expression gets all lines lines from the current window, escapes blanks in the filename and formats them one after another separated by blanks (the format that :vimgrep expects). This should work most of the time, but will probably fail, if there are other nasty characters in the filename. If your pattern contains a '/' you could use any other delimiter, e.g. #pattern#gj or something similar. Otherwise you would have to escape the /. This will fill the quickfix-list with a list of all matches. Use :copen to access the quickfix window. On each result you can simply press Enter and vim will jump right to that file. The j-flag above prevents jumping to the first result and the g-flag ensures that all matches in each file will be added to your result. You can use :cnext to jump to the next and :cprev to jump to the previous match. For more information read the help at :h quickfix :h :vimgrep regards, Christian
-- You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php
