How do I make vim open all files matching a pattern in different tabs?

Viewed 6413

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.

5 Answers

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

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

Related