Sign up ×

Is there anyway to let VIM expand the glob pattern to all files that match it?

e.g when I type *.c, and press some key, it would become a.c b.c

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Take a look at the glob function (:help glob())

For example, this command

:nmap <leader>* ciW<C-r>=substitute(glob(@"),'\n',' ','g')<cr>

defines a normal-mode mapping that replaces the current word with space separated output of glob. Note that it will clobber your " register, which should not be a big deal as long as you keep that caveat in mind. Unfortunately, it does not result in a pretty display because file names themselves often have spaces and may even have newlines.

share|improve this answer
Or: :nmap <leader>* ciW<C-r>=substitute(glob(@"),'\n',' ','g')<cr> –  Stéphane Chazelas Sep 14 '12 at 20:09
@sch Yes that is probably more robust but does sacrifice the " register. I'll put it in. –  jw013 Sep 14 '12 at 20:14

Your Answer


