52

When launching vim from the command line, I can do for example vim *.txt to open all text files in a directory at once.

For some reason, trying the same from inside vim ( :e *.txt ) gives an error: E77: Too many file names.

Is there a reason why vim refuses to open multiple at once? Is there a way to change that?

1
  • I use buffers for multiple files, no need to answer about tabs or split. Sorry, should have mentioned that in the question. Commented Sep 6, 2012 at 16:47

4 Answers 4

82

This should work :

:next *.txt
Sign up to request clarification or add additional context in comments.

4 Comments

Done! I couldn't do it yet when I posted my comment.
If you want to include files in all sub-directories in addition to files in the current directory, use :n **/*.txt
Wonderful!!! I've been looking for this cmd for too long. I do have to say though ":next" is very unintuitive, would be much better to have ":e[dit] *txt" instead!
@mrk Exactly. Opening multiple files is an obvious thing to want to do, so :e should have allowed for that. ":[count]n[ext] [++opt] [+cmd]" means "Edit [count] next file" Er, ok mate, if you say so!
15

It's done in two operations.

Open all *.js files in as many vertical splits:

:argadd *.js
:argdo vs

in horizontal splits:

:argdo sp

in tabs: 

:argdo tabe

1 Comment

I did the horizontal splits version and it did open all files in the dir, but it created four splits for each file.
2

:args *.txt also works.

If it helps there is more information on this topic at :help argument-list and :help 07.2. Both of those sections help explain how to use the argument list and how the buffer list is not the same thing.

Comments

-2

Also, to add to the other answers, when you first start vim you can open multiple files at the same time, e.g.:

vim *.txt

3 Comments

That's what OP tried, but he had the error: E77: Too many file names.
@kenorb No, that works fine, it was :e *.txt that gave errors. The real problem with this is that it doesn't work when vim is already running.
That's literally mentioned the first line of the question.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.