Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 280
Martin Blech Avatar asked Aug 12 '10 14:08

Martin Blech


People also ask

How do I make different tabs in Vim?

You can switch between tabs with :tabn and :tabp , With :tabe <filepath> you can add a new tab; and with a regular :q or :wq you close a tab. If you map :tabn and :tabp to your F7 / F8 keys you can easily switch between files.

How do I open multiple files in vi editor?

1 Invoking vi on Multiple Files one. When you first invoke vi, you can name more than one file to edit, and then use ex commands to travel between the files. invokes file1 first. After you have finished editing the first file, the ex command :w writes (saves) file1 and :n calls in the next file (file2).


1 Answers

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.

like image 177
nicholas a. evans Avatar answered Nov 30 '22 23:11

nicholas a. evans