Vim: Open multiple files in a specified configuration from command line

2

I use a set of tabs and splits in my Vim window for my workflow.

My setup looks something like this:

1st tab with a vertical split showing two buffers. 2nd tab in the following split:

-----------------------------------
|                    |            |
|                    |            |
|                    | Buffer b   |
|                    |            |
|                    |            |
|  Buffer a          |------------|
|                    |            |
|                    |            |
|                    | Buffer c   |
|                    |            |
|--------------------|------------|

Now, how can I start vim such that I get all my files loaded as separate buffers in the about layout? I am too lazy to set up this layout everytime I have to restart my vim for some reason.

darnir

Posted 2014-03-10T12:06:20.930

Reputation: 657

You also seem to be too lazy to at least look up the excellent Vim help and post your attempts with your question. – Ingo Karkat – 2014-03-10T12:26:09.243

Ingo Karkat: Not really. I tried, but couldn't find anything about such a feature on Vim help. – darnir – 2014-03-10T12:36:40.633

Answers

3

Vim supports the -o and -O arguments to influence the split behavior of passed files. Since only one can be specified, and you want an asymmetic layout, you need to adapt this later, with commands that you can pass via -c {Ex-cmd}.

For your second, more interesting layout, one simple way is to start with horizontal splits, and move the first (buffer a) window to the left with <C-w>H.

$ vim -o -c "wincmd H" a b c

I'll leave the addition of the first tab layout as an exercise to you...

Alternative

If the set of files is fixed (and the layout more complex), Vim sessions (cp. :help Session) store the window layout and set of opened files.

Ingo Karkat

Posted 2014-03-10T12:06:20.930

Reputation: 19 513

Tim Pope's vim-obsession and the extension vim-prosession are also amazing plugins extending the :mksession option with sane and fantastic capabilities. – dragon788 – 2018-05-15T17:03:31.990

Yes! Your alternative sounds good. And since my set of files is pretty much fixed, I can use sessions. I didn't know about this feature at all! Thanks a lot! (I'll mark this answer, as soon as I get the sessions working) – darnir – 2014-03-10T12:37:54.717

Though everything is built-in, I can recommend the session.vim plugin, which simplifies the session handling.

– Ingo Karkat – 2014-03-10T13:40:32.463

0

You can also use the vim-layout script that uses the -o, -c arguments automatically and supports different layouts. To get the output you wanted you would simply run:

vl <the three files>

Disclaimer: I wrote the script.

Auxiliary

Posted 2014-03-10T12:06:20.930

Reputation: 325