Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


By posting your answer, you agree to the privacy policy and terms of service.

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