3

Using :h wildignore, I can ignore certain types of files or certain folders when searching through them to open one of them. But that also means those files and directories will be ignored when I try to insert their filepath with :h i_CTRL-X_CTRL-F.

Is there a way I can ignore, say, all jpg files when trying to open them using :edit but not ignore them when trying to insert their filepath using :h i_CTRL-X_CTRL-F in a file?

3
  • 2
    Seconded; I've just noticed this problem when writing LaTeX documents—I can't use <C-x><C-f> to insert image names for including figures!
    – D. Ben Knoble
    Jan 1, 2020 at 21:01
  • 1
    How about this Q&A: Filter file completion list? Does it answer your question too?
    – Matt
    Jan 2, 2020 at 7:14
  • @Matt, yeah, thanks, man. It works perfectly. In fact, it works more perfectly. I can now use **/*.jpg to populate the suggestion list! Freaking awesome man!! Thanks again.
    – 3N4N
    Jan 2, 2020 at 13:48

1 Answer 1

1

One solution I have is to disable 'wildignore' while in Insert mode. I haven't found any untoward side-effects, but it would have been nice to have a pre-complete/post-complete pair of events (CompleteDone is almost pre-complete, but CompleteChanged is not pre).

augroup NoWildignoreInsert
  au!
  au InsertEnter *
        \ if !exists('b:old_wildignore') |
        \   let b:old_wildignore=&wildignore |
        \   set wildignore& |
        \ endif
  au InsertLeave *
        \ if exists('b:old_wildignore') |
        \   let &wildignore=b:old_wildignore |
        \   unlet b:old_wildignore |
        \ endif
augroup END

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