I have four files file1, file2, file3, & file4. So I want to open them with vim directly from command line and get the following structure:

  1. Tabulation 1: file1 taking whole tab
  2. Tabulation 2: file2 and file3 sharing the same tab in split mode
  3. Tabulation 3: file3 taking whole tab

So, how to do it directly from the invocation? I know I can do from vim, when I open it the following command sequences:

:e file1
:tabedit file2  | vsp file3
:tabedit file4

But then, I have two question:

First question — How can I give this script to vim at the invocation and will it produce the expected behavior?

Second question — Is their another building and probably more elegant way to do this file structure without script? I imagine a syntax like this: vim -p file1 [ file2 | file3 ] file4, where the [] means al what we do inside it should be appear in one tab, and the symbol | means the two file should be vertically spited. Is such syntax exist or am I just dreaming about it?

  • 2
    :h session-file could be what you need here. It does not directly let you organize the layout from invocation, but makes it easy to save an existing state which you can then reuse. :mksession session.vim vim -S session.vim.
    – Biggybi
    May 4, 2020 at 11:57

2 Answers 2


Vim’s -S option can take any file of vim commands and run them at startup. It’s usually used for sessions (:mksession; pairs well with tpope’s obsession plugin).

In this case, though, you could make the following file

" mylayout.vim
edit file1
tabedit file2
" &c.

And then you can do vim -S mylayout.vim

  • I think in fact your solution still the best approach. I will let this tread unresolved some days to see if other peoples have other solutions.
    – fauve
    May 5, 2020 at 4:13

I have the answer of my first question: I have to invoque Vim like this vim -c ":edit file1 | tabedit file2 | vsp file3 | tabedit file4.

But, I’m still answering if it doesn’t a more “elegant” way and less verbose to do the same thing?

Your Answer

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

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