477

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
Andrei Chikatilo
  • 5,069
  • 4
  • 17
  • 14

5 Answers5

503

Ctrl+W, S (case does not matter) for horizontal splitting

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

Ctrl+W, q (lower case) to close one

Ctrl+W, Ctrl+W to switch between windows

Ctrl+W, j (or k, h, l; lowercase) to switch to adjacent window (down, up, left, right respectively)

music2myear
  • 40,472
  • 44
  • 86
  • 127
LB40
  • 5,317
  • 2
  • 16
  • 9
  • 13
    To switch screens, Press `Ctrl-w` and then `up arrow` or `down arrow` to switch screens. – Eric Leschinski Oct 17 '12 at 01:20
  • 9
    Ah but you can use regular vim movements, e.g. `ctrl+w j` to jump to the buffer below the current one. – mitjak Oct 04 '13 at 21:00
  • swapped order of down and up for `Ctrl + W` `J`(down) and `Ctrl + W` `K`(up) – pseyfert Nov 30 '16 at 17:02
  • 1
    Thanks this helped me figure out how to move backwards, `Ctrl + w` `left arrow`. I always use `ctrl + ww` to cycle forward. If your on the bottom and need to access a file on the top quickly, and don't want to go forward, you need to move up first with `ctrl + w` `up arrow` before moving left(or right). Thanks. – Brian Thomas May 11 '17 at 20:09
  • @Atav32 I was responding to a comment, not a question, and this is Superuser, not stack overflow. The comment used the wrong term and I asked a simple question in response in an attempt to politely point this out as you can't moderate comments and it's not wrong enough to warrant a flag. Plus it didn't work anyway, no matter what you call it. –  May 09 '18 at 08:12
  • +1 for ctrl-w v. I was gettting really good at typing :vert – smilingfrog May 16 '20 at 23:43
  • @Lucas: Too slow :P – Niing Apr 02 '21 at 15:53
  • For left right split, `Ctrl+W` then `W`, or `Ctrl+W` then `Left/Right Arrow` works. – schulwitz Dec 16 '21 at 00:30
477

From vim --help:

-p[N]  Open N tab pages (default: one for each file)
-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

If N is provided the N windows/tabs will be opened. If N is less than the number of files in arguments, then the remaining files will be loaded in hidden buffers. If N is greater than the number of arguments, the remaining windows/tabs will be editing an empty file.

Laurence Gonsalves
  • 6,031
  • 2
  • 19
  • 18
  • 15
    Really? I've never had to provide an N. – Cascabel Oct 05 '09 at 20:03
  • 3
    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 06 '09 at 03:35
  • 34
    `-o` is like `:split`, `-O` is like `:vsplit` – Evgeni Sergeev Jan 21 '14 at 10:06
  • @Cascabel `-whatever[N]` means that `N` is optional and can be omitted, I believe it derives from standard [ebnf syntax](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form) – user3338098 Jul 24 '18 at 17:21
  • @user3338098 I *think* there may have been a deleted comment here; Laurence's "Indeed..." comment implies that it was causing problems when omitted. – Cascabel Jul 24 '18 at 17:32
  • 2
    @Cascabel `-o without N works as documented.` so omitting N solved the problem. I suspect they were literally doing something like `vim -o[2] file1 file2` which is invalid syntax. – user3338098 Jul 27 '18 at 17:11
393

While running vim:

  1. :sp filename for a horizontal split
  2. :vsp filename or :vs filename for a vertical split
installero
  • 103
  • 4
Taylor Leese
  • 4,383
  • 2
  • 18
  • 16
23

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
dls
  • 331
  • 1
  • 4
2

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

Brent
  • 137
  • 2
  • 15
    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