Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Ignore Special Path in Search


In my .vimrc file, I have two very useful lines:

set path=~/nbapp/**
set backupdir=~/nbapp/temp

The first line allows me to search in my project directory and subdirectories. The second line makes vim create backup files in a special temporary folder, rather than disturbing me by adding tens of backup files having the exact same name except for a '~' at the end. However, since the temporary files are still inside the 'nbapp' folder (and I want to keep them there because they are related to the project), it means they are also going to be searched when I make a search, which sometimes disturb me, because I keep looking at searched results, yet to discover that they are actually in the temporary folder.

Is there any possible way to exclude paths from search (i.e. vimgrep)? I want to exclude the 'temp' folder.

Regards,
Rafid

like image 614
Rafid Avatar asked Nov 28 '10 09:11

Rafid


3 Answers

Use the 'wildignore' option:

:set wildignore+=**/temp/**

or if you would like to be more specific:

:set wildignore+=~/nbapp/temp/**

This should exlude all files in the nbapp/temp directory in :find result.

like image 154
holygeek Avatar answered Nov 18 '22 21:11

holygeek


Instead of vimgrep I use the grep command

:help grep

I use the setting

set grepprg=grep\ -nIh\ --exclude=tags\ --exclude=cscope.out

when I want to search files but excluding the tag files and cscope files. You could modify the above to not search any files ending with a ~. I don't think you can exclude the folder using grep (or maybe you can, try --exclude=~/nbapp/temp/* it might work I haven't tested it).

If that does not work I recomend using ack for the grepprg instead of grep. ack as an option ignore-dir=name in which you can explicitly ignore a folder.

like image 23
skeept Avatar answered Nov 18 '22 21:11

skeept


To exclude some dirs from :find and gf (for example node_modules) you can set:

:set path=**
:set wildignore+=*/node_modules/*
like image 5
itsnikolay Avatar answered Nov 18 '22 22:11

itsnikolay