In vim, I do search with vimgrep frequently. I have mapping like below:
map <leader>s :execute "noautocmd vimgrep /\\<" . expand("<cword>") . "\\>/gj **/*.*" <Bar>
cw<CR> 5
The problem is that there are some temporary subfolders (like obj, objd) that I don't want to search for. How can I exclude subfolders matching given patterns. For example, subfolders with prefix "objd" should not be included in searching.
As of Vim 7.3.570, you can use wildignore to exclude patterns with vimgrep.
For example, to ignore the objd subfolder:
:set wildignore+=objd/**
Additional exclusions can be added by separating patterns with a comma:
:set wildignore+=objd/**,obj/**,*.tmp,test.c
See Vim's help documentation for a few more details.
:help wildignore
For example in Ubuntu just
sudo apt-get install ack-grep
sudo ln -s /usr/bin/ack-grep /usr/bin/ack
then install http://www.vim.org/scripts/script.php?script_id=2572
and now add next line to your .vimrc
noremap <C-f> :copen<CR>:Ack --ignore-dir #first_ignore_dir# --ignore-dir #second_ignore_dir# -ai
- its open search frame by Ctr+F, have fun
来源:https://stackoverflow.com/questions/1898987/how-to-exclude-file-patterns-in-vimgrep