Make Vim glob () also match hidden point files

On Linux or Mac, the Vim glob () function does not match dot files such as .vimrc or .hiddenfile . Is there a way to make it match all files, including hidden ones?

The command I use:

 let s:BackupFiles = glob("~/.vimbackup/*") 

I even tried to set the mysterious {flag} parameter to 1 , and yet it still doesn't return hidden files.

UPDATE: Thanks ib! Here is the result of what I was working on: delete-old-backups.vim

+4
source share
1 answer

This is due to the way the glob() function works: the symbol of one star does not correspond to hidden files by design. The default style used in the shell could be changed for this ( shopt -s dotglob in Bash), but this is not possible in Vim.

However, you have several options to solve the problem. The first and most obvious is to hide the hidden and hidden files separately, and then concatenate the results.

 :let backupfiles = glob(&backupdir.'/*')."\n".glob(&backupdir.'/.[^.]*') 

(Be careful not to receive . And .. along with hidden files.)

Another and probably more convenient way (but less portable, though) is to use backtick expand in the glob() call.

 :let backupfiles = glob('`find '.&backupdir.' -maxdepth 1 -type f`') 

This forces Vim to execute the command inside the backticks to get a list of files. The find lists all files ( -type f ), including hidden ones, in the specified directory ( -maxdepth 1 prohibits recursion).

+3
source

All Articles