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.

Martin Blech
  • 13,135
  • 6
  • 31
  • 35
  • Related: [How can I open multiple tabs at once?](http://vi.stackexchange.com/questions/2108/how-can-i-open-multiple-tabs-at-once) at Vim SE – kenorb Feb 23 '15 at 15:47

5 Answers5

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.

nicholas a. evans
  • 2,163
  • 1
  • 17
  • 17
  • 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`? – Martin Blech Aug 16 '10 at 12:22
  • `set tabpagemax=100` will allow vim to open 100 tabs. – sixtyfootersdude Oct 15 '14 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: https://stackoverflow.com/questions/26708822/why-do-vim-experts-prefer-buffers-over-tabs#26710166) . 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:https://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs/) – Simon C. Aug 05 '18 at 13:49
10

You can use the following:

:next **/test*.py

It opens all the files.

Alex
  • 9,891
  • 11
  • 53
  • 87
Jay Zhuang
  • 321
  • 4
  • 9
  • 1
    how is this not the correct answer? it's much simper ! – Strudle Apr 26 '18 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 05 '18 at 13:35
  • I don't see how this does what was asked. If I try it, just one buffer opens. – Turion Aug 13 '19 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).

rofrol
  • 14,438
  • 7
  • 79
  • 77
  • Or `nmap :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. – Josiah Yoder Dec 04 '14 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

Rigel
  • 101
  • 1
  • 3
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

Sławomir Lenart
  • 7,543
  • 4
  • 45
  • 61