Vim: Ignore Special Path in Search
Asked Answered
Y

5

24


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

Yellowhammer answered 28/11, 2010 at 9:41 Comment(0)
T
28

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.

Thrill answered 29/11, 2010 at 16:4 Comment(2)
I was looking for exactly this, for ignoring build folders in :find searches. Thanks!Somatoplasm
Worked for me in vim 7.4Luing
H
6

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.

Hickox answered 28/11, 2010 at 16:45 Comment(2)
Recent versions of grep has --ignore-dir too, which might be just what you are looking for.Stolid
To not break quickfix window better would be set grepprg=grep\ -n\ --exclude=tags\ --exclude=cscope.out\ $*\ /dev/nullWalkout
S
5

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

:set path=**
:set wildignore+=*/node_modules/*
Shaner answered 7/10, 2017 at 12:26 Comment(4)
Apparently you've never listened to Jimmy SoulConfidence
@WayneWerner I didn't got your comment. Right after 2 years ago :)Shaner
I'm pretty confused at the moment exactly what in the world I meant at the time :DConfidence
set wildignore looks like do nothing when in .vim/ftplugin.Marinara
S
0

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
Stumpage answered 26/5, 2013 at 21:2 Comment(0)
T
-1
set path-=~/nbapp/temp

is the preferred method of removing path entries, as it guards you against vim upgrades that may modify the value of 'path'.

Tempo answered 28/11, 2010 at 16:15 Comment(1)
That doesn't seem to be working! It still shows me the backup files.Yellowhammer

© 2022 - 2024 — McMap. All rights reserved.