Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There must be a way, something like this:

vim -[option] <file-list>

to open files from command prompt and not from within Vim.

  • split windows vertically or/and horizontally
  • in separate tabs
share|improve this question

migrated from Oct 11 '12 at 19:30

This question came from our site for professional and enthusiast programmers.

up vote 244 down vote accepted

I'm assuming you mean from the command line. From vim --help:

-o[N]                Open N windows (default: one for each file)
-O[N]                Like -o but split vertically

So type this to open files split horizontally, for example:

vim -o file1.txt file2.txt file3.txt
share|improve this answer
Really? I've never had to provide an N. – Jefromi Oct 5 '09 at 20:03
Indeed, it seems to be something in my .vimrc causing the trouble. If I move it aside, -o without N works as documented. – Laurence Gonsalves Oct 6 '09 at 3:35
-o is like :split, -O is like :vsplit – Evgeni Sergeev Jan 21 '14 at 10:06

Ctrl+W, S (upper case) for horizontal splitting

Ctrl+W, v (lower case) for vertical splitting

Ctrl+W, Q to close one

Ctrl+W, Ctrl+W to switch between windows

Ctrl+W, J (xor K, H, L) to switch to adjacent window (intuitively up, down, left, right)

share|improve this answer
To switch screens, Press Ctrl-w and then up arrow or down arrow to switch screens. – Eric Leschinski Oct 17 '12 at 1:20
@EricLeschinski, I prefer ctrl+w ctrl+w to cycle through windows as arrow keys feel a little anti-vi – Lucas Jan 27 '13 at 20:39
Ah but you can use regular vim movements, e.g. ctrl+w j to jump to the buffer below the current one. – mitjak Oct 4 '13 at 21:00
:q also closes window – Alexandre Bourlier Dec 29 '14 at 16:52
Ctrl+w to switch windows doesn't seem to work on mac terminal. Ctrl+w,w does though – slashdottir Jun 26 '15 at 21:23

While running vim:

  1. :sp filename for a horizontal split
  2. :vsp filename or :vs filename for a vertical split
share|improve this answer
This doesn't answer the question raised...but it SURE helped me out :D Thanks! – Abel Mar 24 '11 at 18:45
Many thanks for it. It's exactly what I need it! – mapcuk Mar 16 '12 at 8:43
thanks, just what I was looking for. I also :set splitright – zack Aug 7 '12 at 23:44
ctrl-ww for switching between splits – Nerrve Feb 17 '14 at 9:29

another interested trick is the CLI -p argument - which opens them in separate tabs for recent versions of vim and gvim.

gvim -p file1.txt file2.txt
share|improve this answer

Another useful trick that I just found out, is that you can use wildcards in the filelist to open multiple files. Say you want to open file1.txt, file2.txt, and file3.txt all in separate tabs but don't feel like typing that all out you can just do:

vim -p file*

I frequently find myself needing to open a lot of files with a similar prefix, and this has been quite helpful

share|improve this answer
That does not have to do with Vim itself but with the shell you are using. It is the shell that expands globs. – Kazark Aug 24 '12 at 19:16
Good to know, thanks! – Brent Aug 24 '12 at 23:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .