5

Suppose I open multiple files in vim like this:

vim a.cc b.cc x.cc

vim will open all files, but show only one at a time, the rest being accessible using the :next command.

After having these files opened, how to spread them into a split view, like if I had used the -O flag when opening them? Also, it would be nice to know how can I spread them into tabs too.

6

Here are a bunch of helpful commands for you:

To open every buffer in a horizontal split:

:sball

To open every buffer in a vertical split:

:vert sball

You can do the same thing with tabs, e.g, to open every buffer into its own tab:

:bufdo tab split

If you would like more control over how they get split, you can do this individually.

First, list every open buffer with:

:ls

Then you can choose what to do for each buffer.

To open buffer N in a horizontal split:

:sb N

sb is an abbreviation of :sbuffer

To open buffer N in a vertical split:

:vert sb N

To open buffer N in a new tab:

:tabedit | bN
  • 1
    Don't forget about :sball. :) – Tumbler41 Aug 26 '16 at 20:29
  • From your answer and the comment above, I could derive what I actually wanted: :vert sball. Thanks folks. – Kira Aug 26 '16 at 20:32
  • @Kira I was actually just about to add that into my answer, but still I'm glad that I could help! – DJMcMayhem Aug 26 '16 at 20:33
  • BTW, I feel :bufdo tab split does not quite do what you intend to do. If you open files like vim a b c, then run that command, you will end up with 4 open files, a b c c. IDK why though, but I tested it here. – Kira Aug 26 '16 at 20:36
  • @Kira You're right, I'm not sure what causes that. You could do :exe "bufdo tab split" | q, but that seems kinda hacky. – DJMcMayhem Aug 26 '16 at 20:39

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.