Robert Kusznier
Robert Kusznier

Reputation: 6911

Difference between * and ** in Vim file search patterns

I read Vim's help on file-searching where * and ** file searching operators are explained (both cited below). While I grasp that ** matches only directories (with limitation of 30 directories deep by default) and * matches everything (including /), I don't think I understand why there is a need for both of them and what are the use cases for each.

Also, how to match only the files in the listed directory? directory/* would match files in subdirectories (e.g. directory/subdirectory/) as well, right? Wouldn't they compliment each other better if * would match only files in the listed directory (without subdirectories)?

Vim documentation:

The usage of '*' is quite simple: It matches 0 or more characters.  In a
search pattern this would be ".*".  Note that the "." is not used for file
searching.

'**' is more sophisticated:
   - It ONLY matches directories. 
   - It matches up to 30 directories deep by default, so you can use it to
     search an entire directory tree
   - The maximum number of levels matched can be given by appending a number
     to '**'.

Upvotes: 2

Views: 786

Answers (1)

Jan Hudec
Jan Hudec

Reputation: 76236

  1. No, just like in wildcards, * does not match /.
  2. In all of the (quite few) cases where these are used, vim is either only looking for files or only looking for directories, so there is no problem with directories matching where you want files.

Upvotes: 2

Related Questions