Search code examples
vimglob

how to exclude files when using globpath() function


I want to obtain in Vim any file in a path that doesn't have a .tex or .bib extension.

I tried (in order to ignore tex files) the following command

:echo globpath({some path}, '*.[^tex]*')

but that will also ignore combinations of tex characters (for instance .toc files).

So how can I modify the pattern in order to match any file without .tex or .bib extension?

Edit: Vim' negative lookahead is done with \@!. I have a directory /test with the files foo.bib, foo.tex, foo.pdf, foo.aux and foo.toc. I tried doing

:echo globpath('C:/Users/Pedro/Desktop/test', '\w*\.\%\(tex\|bib\)\@!')

but that returns an empty string.


Solution

  • to use globpath() function, you don't need regex. it's a glob function. you can just set the wig option (wildignore) , then call the function .

    set wig=*.bib,*.tex
    

    then

    :echo globpath('/your/path','*.*')
    

    do a test:

    kent$  pwd
    /tmp/test
    
    kent$  ls -1
    bar.bib
    bib.bar
    f.txt
    tex.foo
    x.tex
    

    in vim:

    :set wig=*.bib,*.tex
    :echo globpath('/tmp/test','*')
    

    we got:

    /tmp/test/bib.bar
    /tmp/test/f.txt
    /tmp/test/tex.foo
    

    note that you can call it globpath('/path','*',0,1) to have returned value in a list, sometimes it is handy to use in script.