4

The :help entry for "wildignore" directs me to the following list of file patterns under *autocmd-patterns*:

The pattern is interpreted like mostly used in file names:
    *   matches any sequence of characters; Unusual: includes path
        separators
    ?   matches any single character
    \?  matches a '?'
    .   matches a '.'
    ~   matches a '~'
    ,   separates patterns
    \,  matches a ','
    { } like \( \) in a |pattern|
    ,   inside { }: like \| in a |pattern|
    \}  literal }
    \{  literal {
    \\\{n,m\}  like \{n,m} in a |pattern|
    \   special meaning like in a |pattern|
    [ch]    matches 'c' or 'h'
    [^ch]   match any character but 'c' and 'h'

I can't seem to be able to get the \\\{n,m\} working, however. When I try, for example, adding

set wildignore+=ntuser.dat.log[0-9]\\\{1,\}

to my vimrc, I get the error message E220: Missing }. Have I misunderstood something?

6
  • Yes, it says the error was detected while processing my vimrc and refers to a lambda function. My vimrc sources error-free if I remove the wildignore setting. I still get the error with vim --noplugin
    – user38527
    Oct 28, 2021 at 0:03
  • If I delete the lambda functions in my vimrc along with --noplugin, then I don't get an error at first, but I get the error once I start loading buffers. In any case, the wildignore setting doesn't seem to have worked after testing with glob().
    – user38527
    Oct 28, 2021 at 0:12
  • Hmm. Not sure. BTW, have you tested it directly/manually (i.e. open vim and enter/run the set command)? Always good to verify it that way before trying it in your vimrc, if you haven't already.
    – B Layer
    Oct 28, 2021 at 0:23
  • 1
    Welcome to Vi and Vim!
    – filbranden
    Oct 28, 2021 at 0:24
  • 2
    Thanks for the welcome @filbranden, I came here upon the recommendation in Vim's README.md
    – user38527
    Oct 28, 2021 at 1:02

1 Answer 1

2

There are two issues here.

First, 'wildignore' takes a list of separate patterns, split by comma, so you actually need to escape the comma with a backslash for it to work inside the \\\{n,m\} pattern inside 'wildignore'. So what you actually need as a value is ntuser.dat.log[0-9]\\\{1\,\}.

But, second, the :set command will use backslash as an escape character, so in order to get one backslash in the actual value of the option, you need to pass it two (the first one to escape the second.) So, in effect, you need to double the backslashes that you pass.

This is the actual command that works:

set wildignore+=ntuser.dat.log[0-9]\\\\\\{1\\,\\}

Note that if you use :set wildignore? to inspect it later on, you'll see the actual value with the correct number of backslashes, three before the { and one before the , and } each.


I tested this setup with files named ntuser.dat.log followed by numbers (of varying lengths) and non-numbers that would not match the pattern. It seemed to work as expected for me.

If you want to reproduce my testing:

  • Create a test directory and cd into it:
$ mkdir ~/testwildignore
$ cd ~/testwildignore
  • Create files named after the wildignore pattern to test:
$ touch ntuser.dat.log ntuser.dat.log0000000 ntuser.dat.log00000001123 ntuser.dat.log0 ntuser.dat.log00000001122348y3249873297498 ntuser.dat.log99

Of these, all are ignored except for two, the one with no numbers and the one with a letter (y) among the numbers.

  • Create a local test vimrc with only two lines:
$ cat test_vimrc
set wildmenu
set wildignore+=ntuser.dat.log[0-9]\\\\\\{1\\,\\}
  • Start Vim with this vimrc:
$ vim -N --noplugin -u test_vimrc
  • Inside Vim, type :e, space, then Tab.

The wildmenu you see will only include:

ntuser.dat.log  ntuser.dat.log00000001122348y3249873297498  test_vimrc
:e ntuser.dat.log

As you can see, all files except the two that don't match the pattern have been filtered out.

7
  • 1
    Ugh. Welcome to backslash hell. :P
    – B Layer
    Oct 28, 2021 at 0:25
  • With your command it doesn't give me the error anymore, but I still have the files show up in the wildmenu with a vimrc containing only the command along with set wildmenu.
    – user38527
    Oct 28, 2021 at 0:34
  • 1
    This is a good opportunity to use let & with single quotes
    – D. Ben Knoble
    Oct 28, 2021 at 11:38
  • 1
    @D.BenKnoble One problem with let & is that it makes it hard to emulate the behavior of set +=, which will append a new item and properly add commas when needed...
    – filbranden
    Oct 28, 2021 at 16:45
  • @user38527 I updated the answer to include the full set of commands I used to test this setup, and it seems to work as expected for me... If it doesn't work for you, can you please update the question with the steps you're using and what you're seeing that's unexpected (or which files are not being ignored that should)?
    – filbranden
    Oct 28, 2021 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.