23

In a given working directory, if I do

:tabe **/test*.py

vim complains with E77: Too many file names. What if I want it to open every matching file in a separate tab? There must be a way to do it, but I can't find it.

1

5 Answers 5

35

You could use the args list and argdo like so:

:args **/test*.py
:argdo tabe %

However, the syntax event is turned off by argdo (to speed up the normal use case), so the files will be loaded without syntax at first. You could follow it up with a :syntax on to force the syntax event on all loaded buffers. Compressed into one line (need to wrap argdo in execute so it doesn't absorb the following |):

:args **/test*.py | execute 'argdo tabe %' | syntax on

Alternately, you can open vim from the command line via:

vim -p **/test*.py

But that will max out at 10 tabs.

3
  • 2
    thanks a lot! now, how could I make the pattern a parameter so I can map the script to a new command and I can do, e.g. :tabeall **/test*.py? Aug 16, 2010 at 12:22
  • set tabpagemax=100 will allow vim to open 100 tabs. Oct 15, 2014 at 17:21
  • As said below, the answer by @cooldoger is much quicker, shorter and easier. I guess that problem here is the good old vim confusion between "tabs" and "bufffers" (cf: stackoverflow.com/questions/26708822/…) . I don't think it's useful to open 100 tabs, better to use buffers instead, and learn how to use them right (cf here for example:joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs)
    – Simon C.
    Aug 5, 2018 at 13:49
10

You can use the following:

:next **/test*.py

It opens all the files.

3
  • 1
    how is this not the correct answer? it's much simper !
    – Strudle
    Apr 26, 2018 at 11:57
  • I agree that this answer is much better, simpler and faster, but as the question ask for "different tabs" I guess that the accepted answer is the good one.
    – Simon C.
    Aug 5, 2018 at 13:35
  • I don't see how this does what was asked. If I try it, just one buffer opens.
    – Turion
    Aug 13, 2019 at 15:53
1

To map it

nmap <c-d> :args **/*.tpl<bar>execute 'argdo tabe %'<bar>syntax on<cr>

But still it displays list of files, you have to press enter few times (depending of number of files).

1
  • Or nmap <c-d> :args **/*.tpl ^M argdo tabe % ^M syntax on ^M Use Control-Q to type the ^M (literal newline) character. Still displays the list of files, though. Dec 4, 2014 at 18:30
0

This functionality can be included as a command in your .vimrc file:

"open all files in seperate tabs
command -nargs=1 OpenAll call <SID>openAll(<f-args>)
function! s:openAll(dir)
    execute 'args ' . a:dir
    silent argdo tabe %
    syntax on
endfunction

With this function running :OpenAll **/*.py from vim will quickly open all files into new tabs

0

None of the other answers works for me, but this is fine:

find <path> -iname <pattrn> | xargs -o vim -p
  • all files are visible in different tabs
  • file lookup is recursive

Note, vim can limit tabs - to be changed by set tabpagemax=42.

Also, if you wonder how to close all tabs at once, use :qa

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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