How can I make vim :find only files with .c or .h extensions?

For example, I am interested in finding .c files starting with tsv so I would run :find tsv*. This gives too many results; how do I make it specific to .c?

  • Doesn't :find tsv*c or :find tsv*\.c work?
    – statox
    Mar 23 '21 at 9:03
  • it does but not sure how to look for .c and .h files together, ex: something like :find tsv*.{c,h} Mar 23 '21 at 9:17
  • 2
    Ah, then :find tsv*[hc] should do the trick.
    – statox
    Mar 23 '21 at 9:22
  • It does, can you please add this as an answer I will accept Mar 23 '21 at 9:25
  • Welcome to Vi and Vim!
    – D. Ben Knoble
    Mar 23 '21 at 13:44

:find uses regexes as the regular search does. If you look at :h /[] you'll see that using [] in a pattern allows to search for a collection:

    A collection.  This is a sequence of characters enclosed in brackets.
    It matches any single character in the collection.
    Example     matches ~
    [xyz]       any 'x', 'y' or 'z'
    [a-zA-Z]$   any alphabetic character at the end of a line

So your pattern should be :find tsv*[hc]

  • 1
    Thanks for the clear answer Mar 23 '21 at 9:37
  • Its more glob than regex, no?
    – D. Ben Knoble
    Mar 23 '21 at 12:24
  • Good point Ben, that' probably more related to globbing
    – statox
    Mar 23 '21 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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