In a Linux or Mac environment, Vim’s glob() function doesn’t match dot files such as .vimrc or .hiddenfile. Is there a way to get it to match all files including hidden ones?
The command I’m using:
let s:BackupFiles = glob("~/.vimbackup/*")
I’ve even tried setting the mysterious {flag} parameter to 1, and yet it still doesn’t return the hidden files.
Update: Thanks ib! Here’s the result of what I’ve been working on: delete-old-backups.vim.
That is due to how the
glob()function works: A single-star patterndoes not match hidden files by design. In most shells, the default
globbing style can be changed to do so (e.g., via
shopt -s dotglobin Bash), but it is not possible in Vim, unfortunately.
However, one has several possibilities to solve the problem still.
First and most obvious is to glob hidden and not hidden files
separately and then concatenate the results:
(Be careful not to fetch the
.and..entries along with hidden files.)Another, perhaps more convenient but less portable way is to use
the backtick expansion within the
glob()call:This forces Vim to execute the command inside backticks to obtain
the list of files. The
findshell command lists all files (-type f)including the hidden ones, in the specified directory (
-maxdepth 1forbids recursion).