windows horizontally and vertically as much as you like,
you can create almost any layout of windows. Then you can use these commands
to move between them:
CTRL-W h move to the window on the left
CTRL-W j move to the window below
CTRL-W k move to the window above
CTRL-W l move to the window on the right
CTRL-W t move to the TOP window
CTRL-W b move to the BOTTOM window
You will notice the same letters as used for moving the cursor. And the
cursor keys can also be used, if you like.
More commands to move to other windows: |Q_wi|.
==============================================================================
*08.5* Moving windows
You have split a few windows, but now they are in the wrong place. Then you
need a command to move the window somewhere else. For example, you have three
windows like this:
>
+----------------------------------+
|/* file two.c */ |
|~ |
|~ |
|two.c=============================|
|/* file three.c */ |
|~ |
|~ |
|three.c===========================|
|/* file one.c */ |
|~ |
|one.c=============================|
| |
+----------------------------------+
<
Clearly the last one should be at the top. Go to that window (using CTRL-W w)
and then type this command: >
CTRL-W K
This uses the uppercase letter K. What happens is that the window is moved to
the very top. You will notice that K is again used for moving upwards.
When you have vertical splits, CTRL-W K will move the current window to the
top and make it occupy the full width of the Vim window. If this is your
layout:
>
+-------------------------------------------+
|/* two.c */ |/* three.c */ |/* one.c */ |
|~ |~ |~ |
|~ |~ |~ |
|~ |~ |~ |
|~ |~ |~ |
|~ |~ |~ |
|two.c=========three.c=========one.c========|
| |
+-------------------------------------------+
<
Then using CTRL-W K in the middle window (three.c) will result in:
>
+-------------------------------------------+
|/* three.c */ |
|~ |
|~ |
|three.c====================================|
|/* two.c */ |/* one.c */ |
|~ |~ |
|two.c==================one.c===============|
| |
+-------------------------------------------+
<
The other three similar commands (you can probably guess these now):
CTRL-W H move window to the far left
CTRL-W J move window to the bottom
CTRL-W L move window to the far right
==============================================================================
*08.6* Commands for all windows
When you have several windows open and you want to quit Vim, you can close
each window separately. A quicker way is using this command: >
:qall
This stands for "quit all". If any of the windows contain changes, Vim will
not exit. The cursor will automatically be positioned in a window with
changes. You can then either use ":write" to save the changes, or ":quit!" to
throw them away.
If you know there are windows with changes, and you want to save all these
changes, use this command: >
:wall
This stands for "write all". But actually, it only writes files with
changes. Vim knows it doesn't make sense to write files that were not
changed.
And then there is the combination of ":qall" and ":wall": the "write and
quit all" command: >
:wqall
This writes all modified files and quits Vim.
Finally, there is a command that quits Vim and throws away all changes: >
:qall!
Be careful, there is no way to undo this command!
OPENING A WINDOW FOR ALL ARGUMENTS
To make Vim open a window for each file, start it with the "-o" argument: >
vim -o one.txt two.txt three.txt
This results in:
>
+-------------------------------+
|file one.txt |
|~ |
|one.txt========================|
|file two.txt |
|~ |
|two.txt========================|
|file three.txt |
|~ |
|three.txt======================|
| |
+-------------------------------+