Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer

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
1  
Or: :nmap <leader>* ciW<C-r>=substitute(glob(@"),'\n',' ','g')<cr> –  Stephane 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
add comment

Your Answer

 
discard

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.