How to get vim to open multiple files into tabs at once
Solution 1
:tab all
will open all the files in Vim's argument list in individual tabs. The argument list is initially set to the list of file names given on the command line when Vim is started. The list may be changed with the :args
and related commands. See
:help :all
:help argument-list
Example:
:args *.c
:tab all
will open all the .c files in the current directory in individual tabs.
Solution 2
You actually can open new tabs and keep your current tabs without writing new functions. See this answer on Stack Overflow: https://stackoverflow.com/a/11430615/200234
:args file1 file2 | argdo tabe
You may want to open a new empty tab (:tabe
) before doing that, because the first file will open in the current tab. Also, an extra empty tab will be left open (see :help argdo
to understand why).
Solution 3
To open files in new tabs without replacing the arguments or tabs that are already open:
:argadd *.c | tab all
This was mentioned in a comment but I think deserves its own answer.
Also, to search for files in subdirectories:
:argadd code/**/*.c | tab all
Related videos on Youtube
ahnniu
Updated on September 17, 2022Comments
-
ahnniu over 1 year
Is it possible to get vim to open multiple files into tabs, similar to the way the
args <path>
command will open multiple files into buffers?Doing something like
:tabe ./*
results in the error "E77: Too many file names", even though the number of files is less than the value set in thetabpagemax
property.(I believe the
vim -p <files>
option will open in tabs, but I'm hoping to find a way to do it when vim is already open.)-
Admin over 10 yearsThanks for mentioning the -p option; that's what I was looking for
-
Admin over 9 yearsI found this question via Google. I was looking for how to open vim with tabs from the command line,
vim -p
was what I was looking for :-) -
Admin about 9 yearsRelated: How can I open multiple tabs at once? at Vim SE
-
Admin about 9 yearsRelated: Open several files in new tabs with VIM at Stack Overflow.
-
Admin over 8 yearsRelated: How to open many tabs for many files in vim? at Super User.
-
-
ahnniu over 13 yearsI'm not sure how this is meant to work. Say if I want to open all .txt files in the current directory, what would I enter? If I enter
:tab all *.txt
, vim counters with "E488: Trailing characters" -
garyjohn over 13 yearsI edited the answer to clarify what I meant by "arguments". I meant Vim's argument list rather than arguments to
:tab all
. -
ahnniu over 13 yearsNice, got it now. The only thing that could make this better is a one line equivalent...what do you think the chances are?
-
garyjohn over 13 yearsI don't know of a single command that can do that, but you can put two commands on one line by separating them with a vertical bar, like this:
:args *.c | tab all
. -
Kevin Qi almost 12 yearsThe downside is that using
:tab all
replaces your existing tabs. Because of this, in my use case, it doesn't provide much benefit over reopening files withvim -p
. However, if there were some way to stuff existing tabs into:args
, it might be possible to open new tabs and keep the existing ones. -
Reina Abolofia almost 11 yearsThis worked great for me. I wanted to open all files in my directory with the same extension. This did the trick. Thanks so much.
-
cdosborn almost 9 yearsIf a tab is already open, substitute
argadd
forargs
. -
Damien Bezborodow about 8 yearsThis is great. It also works from the command line. If you do
vim *
in bash, then:tab all
in vim, you can open all the contents of a directory in separate tabs. -
Blaszard over 5 yearsDoes this work on neovim? In my case this only works on vim...
-
jpaugh over 4 yearsIf you're adding new tabs to an existing set, wouldn't it be easier just to
:tabe file1
? -
Mihai Capotă over 4 years@jpaugh, the question is about multiple files.
-
jpaugh over 4 yearsWouldn't
:args | argdo tabe
answer the question, though? What's the reason for adding new files this way? -
Mihai Capotă over 4 years@jpaugh, this is what the question asks for: "I believe the vim -p <files> option will open in tabs, but I'm hoping to find a way to do it when vim is already open."
-
mindthief over 2 yearsThis did what I needed! I used a wildcard
:args *.c | argdo tabe
With the top answer it was opening some files in windows and some in tabs, but this opens all of them in tabs.