Hello Vim developers,
Someone on the Vim subreddit complained that :vimgrep does not obey the
'wildignore' setting, and therefore (slowly) searches files that the user never
wants to edit.
http://www.reddit.com/r/vim/comments/vqzqc/ignoring_files_in_vimgrep/
A similar question was asked on vim_dev in 2008, but never received an answer:
http://groups.google.com/group/vim_dev/browse_thread/thread/a9ad4995318e09dd/e2d3ce2a2306cdcb?lnk=gst&q=vimgrep+wildignore#e2d3ce2a2306cdcb
I interpret the 'wildignore' option as "anything in there, I never want to open
in Vim", and think that it should apply to :vimgrep as well:
1. for consistency with similar functions such as :args {arglist}, which ignores
files in 'wildignore'
2. because the ultimate goal of it is opening files in Vim, and 'wildignore' is
an exclude list that the user declared not being interested in opening
3. because it can significantly speed up :vimgrep (this is what the OP
complained about), avoid clutter in the resulting quickfix list
4. a nice side effect is that files in 'suffixes' are searched last
5. because with :grep, an alternative that matches any file exists
6. plugins with (a rare, unlikely) special need can temporarily reset
'wildignore'
Attached "vimgrep obeys wildignore.patch" implements this. There's only one
other use of the affected get_arglist_exp() function, in :mkspell. I think that
there, 'wildignore' should not apply (though interference with spell files
should be highly unlikely), so the change is a little bit more complex than just
swapping one function call for another.
"vimgrep obeys wildignore docs.patch" documents the new :vimgrep behavior.
Additionally, I think that the documentation for 'wildignore' itself is a bit
incomplete, so I'm re-attaching "wildignore docs enhancement.patch", an edited
version of what I had already sent to this list in an earlier discussion about
backtick-expansion.
-- regards, ingo
--
-- Ingo Karkat -- /^-- /^-- /^-- /^-- /^-- /^-- http://ingo-karkat.de/ --
-- http://vim.sourceforge.net/account/profile.php?user_id=9713 --
--
You received this message from the "vim_dev" 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
diff -r dbb084863466 src/ex_cmds2.c
--- a/src/ex_cmds2.c Wed Jun 20 22:56:02 2012 +0200
+++ b/src/ex_cmds2.c Fri Jun 29 11:16:10 2012 +0200
@@ -1850,22 +1850,28 @@
#if defined(FEAT_QUICKFIX) || defined(FEAT_SYN_HL) || defined(PROTO)
/*
* Parse a list of arguments (file names), expand them and return in
- * "fnames[fcountp]".
+ * "fnames[fcountp]". When "wig" is TRUE, removes files matching 'wildignore'.
* Return FAIL or OK.
*/
int
-get_arglist_exp(str, fcountp, fnamesp)
+get_arglist_exp(str, fcountp, fnamesp, wig)
char_u *str;
int *fcountp;
char_u ***fnamesp;
+ int wig;
{
garray_T ga;
int i;
if (get_arglist(&ga, str) == FAIL)
return FAIL;
- i = gen_expand_wildcards(ga.ga_len, (char_u **)ga.ga_data,
- fcountp, fnamesp, EW_FILE|EW_NOTFOUND);
+ if (wig == TRUE)
+ i = expand_wildcards(ga.ga_len, (char_u **)ga.ga_data,
+ fcountp, fnamesp, EW_FILE|EW_NOTFOUND);
+ else
+ i = gen_expand_wildcards(ga.ga_len, (char_u **)ga.ga_data,
+ fcountp, fnamesp, EW_FILE|EW_NOTFOUND);
+
ga_clear(&ga);
return i;
}
diff -r dbb084863466 src/proto/ex_cmds2.pro
--- a/src/proto/ex_cmds2.pro Wed Jun 20 22:56:02 2012 +0200
+++ b/src/proto/ex_cmds2.pro Fri Jun 29 11:16:10 2012 +0200
@@ -42,7 +42,7 @@
int check_fname __ARGS((void));
int buf_write_all __ARGS((buf_T *buf, int forceit));
int get_arglist __ARGS((garray_T *gap, char_u *str));
-int get_arglist_exp __ARGS((char_u *str, int *fcountp, char_u ***fnamesp));
+int get_arglist_exp __ARGS((char_u *str, int *fcountp, char_u ***fnamesp, int
wig));
void set_arglist __ARGS((char_u *str));
void check_arg_idx __ARGS((win_T *win));
void ex_args __ARGS((exarg_T *eap));
diff -r dbb084863466 src/quickfix.c
--- a/src/quickfix.c Wed Jun 20 22:56:02 2012 +0200
+++ b/src/quickfix.c Fri Jun 29 11:16:10 2012 +0200
@@ -3189,7 +3189,7 @@
;
/* parse the list of arguments */
- if (get_arglist_exp(p, &fcount, &fnames) == FAIL)
+ if (get_arglist_exp(p, &fcount, &fnames, TRUE) == FAIL)
goto theend;
if (fcount == 0)
{
diff -r dbb084863466 src/spell.c
--- a/src/spell.c Wed Jun 20 22:56:02 2012 +0200
+++ b/src/spell.c Fri Jun 29 11:16:10 2012 +0200
@@ -8553,7 +8553,7 @@
}
/* Expand all the remaining arguments (e.g., $VIMRUNTIME). */
- if (get_arglist_exp(arg, &fcount, &fnames) == OK)
+ if (get_arglist_exp(arg, &fcount, &fnames, FALSE) == OK)
{
mkspell(fcount, fnames, ascii, eap->forceit, FALSE);
FreeWild(fcount, fnames);
diff -r dbb084863466 runtime/doc/quickfix.txt
--- a/runtime/doc/quickfix.txt Wed Jun 20 22:56:02 2012 +0200
+++ b/runtime/doc/quickfix.txt Fri Jun 29 10:26:42 2012 +0200
@@ -561,7 +561,9 @@
*:vim* *:vimgrep* *E682* *E683*
:vim[grep][!] /{pattern}/[g][j] {file} ...
Search for {pattern} in the files {file} ... and set
- the error list to the matches.
+ the error list to the matches. Files matching
+ 'wildignore' are ignored; files in 'suffixes' are
+ searched last.
Without the 'g' flag each line is added only once.
With 'g' every match is added.
diff -r ca39f14c1ec3 runtime/doc/editing.txt
--- a/runtime/doc/editing.txt Thu Jun 14 20:59:25 2012 +0200
+++ b/runtime/doc/editing.txt Fri Jun 15 17:05:30 2012 +0200
@@ -377,8 +377,9 @@
embedded spaces must be escaped with a backslash.
*wildcard* *wildcards*
-Wildcards in {file} are expanded. Which wildcards are supported depends on
-the system. These are the common ones:
+Wildcards in {file} are expanded, but as with file completion, 'wildignore'
+and 'suffixes' apply. Which wildcards are supported depends on the system.
+These are the common ones:
? matches one character
* matches anything, including nothing
** matches anything, including nothing, recurses into directories
diff -r ca39f14c1ec3 runtime/doc/options.txt
--- a/runtime/doc/options.txt Thu Jun 14 20:59:25 2012 +0200
+++ b/runtime/doc/options.txt Fri Jun 15 17:05:30 2012 +0200
@@ -7841,9 +7841,9 @@
{not available when compiled without the |+wildignore|
feature}
A list of file patterns. A file that matches with one of these
- patterns is ignored when completing file or directory names, and
- influences the result of |expand()|, |glob()| and |globpath()| unless
- a flag is passed to disable this.
+ patterns is ignored when expanding |wildcards|, completing file or
+ directory names, and influences the result of |expand()|, |glob()| and
+ |globpath()| unless a flag is passed to disable this.
The pattern is used like with |:autocmd|, see |autocmd-patterns|.
Also see 'suffixes'.
Example: >