0

I am looking for a way to open all files in my path that match a regex such as 'MyFileName*.cpp".

I was hoping that the command below would open all matching files in tabs. But it opens a list of files and allows me to select one to open.

:tabf MyFileName*.cpp

A few things to note of what I am looking for:

  • only search files in the vim path. Any ** globbing takes too long and I would rather open each file one by one at that point.

  • It needs to work from within vim. (not vim -p)

ostler.c
  • 3,282
  • 3
  • 21
  • 21

3 Answers3

2

The solution I came up with is here:

function! OpenAll(arg)
    let args=globpath(&path, a:arg)
    for temp_file in split(args, '\n')
        silent exec "tabe ".temp_file
        silent exec "tabr"
    endfor
endfunction

com! -nargs=1 Tabf call OpenAll('<args>')

Then all you have to do is the following

:Tabf MyFileName*.cpp

ostler.c
  • 3,282
  • 3
  • 21
  • 21
  • 1
    Nice solution. By the way, I'm not sure that reading your question is really clear you were searching for something like that. Maybe you could accept your own answer and edit the question just a bit. – lucapette Nov 10 '11 at 08:58
  • Sorry if it was confusing I will change it now. I am hoping someone has a more elegant solution than mine. But if no-one else has a solution in a few days I will accept this one. – ostler.c Nov 10 '11 at 17:21
0

You could use the -p or the -o options like:

vim -p *.cpp
lucapette
  • 20,564
  • 6
  • 65
  • 59
  • I know about vim -p. What I am specifically looking for is a solution from within vim that uses the path variable – ostler.c Nov 09 '11 at 23:17
0

You could use

:args MyFileName*.cpp
:argdo tabf %
kvthanga
  • 49
  • 1
  • That looked promising, but after the first command, it opens a tab called MyFileName*.cpp, then when I try :argdo it can't find the file 'MyFileName*.cpp". It seems like your command would be equal to :tabf MyFileName*.cpp which is the same thing that I was trying. – ostler.c Nov 09 '11 at 23:40
  • From the description it appears that vim is not able to find any file to match the pattern MyFileName*.cpp. – kvthanga Nov 10 '11 at 00:07
  • There is a better solution posted [here](http://stackoverflow.com/questions/3468763/how-do-i-make-vim-open-all-files-matching-a-pattern-in-different-tabs) – kvthanga Nov 10 '11 at 00:09
  • I am able to do your solution without using the path. This requires a lot of time and I really am hoping for something that only looks inside my path instead of every directory from some point on. – ostler.c Nov 10 '11 at 00:24