Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
:splitThis command splits the screen into two windows and leaves the cursor in the top one:
+----------------------------------+ |/* file one.c */ | |~ | |~ | |one.c=============================| |/* file one.c */ | |~ | |one.c=============================| | | +----------------------------------+
CTRL-W
w command can be used to jump between the windows. If you are in
the top window, CTRL-W
w jumps to the window below it. If you are in the
bottom window it will jump to the first window. (CTRL-W
CTRL-W
does the same
thing, in case you let go of the CTRL key a bit later.):closeActually, any command that quits editing a file works, like ":quit" and "ZZ". But ":close" prevents you from accidentally exiting Vim when you close the last window.
:onlyThis closes all windows, except for the current one. If any of the other windows has changes, you will get an error message and that window won't be closed.
08.2
Split a window on another file:split two.cIf you were editing one.c, then the result looks like this:
+----------------------------------+ |/* file two.c */ | |~ | |~ | |two.c=============================| |/* file one.c */ | |~ | |one.c=============================| | | +----------------------------------+
:newYou can repeat the ":split" and ":new" commands to create as many windows as you like.
08.3
Window size:3split alpha.cFor existing windows you can change the size in several ways. When you have a working mouse, it is easy: Move the mouse pointer to the status line that separates two windows, and drag it up or down.
CTRL-W +To decrease it:
CTRL-W -Both of these commands take a count and increase or decrease the window size by that many lines. Thus "4
CTRL-W
+" make the window four lines higher.{height}CTRL-W _That's: a number
{height}
, CTRL-W
and then an underscore (the - key with Shift
on English-US keyboards).
To make a window as high as it can be, use the CTRL-W
_ command without a
count.08.4
Vertical splits:vsplitor:
:vsplit two.cThe result looks something like this:
+--------------------------------------+ |/* file two.c */ |/* file one.c */ | |~ |~ | |~ |~ | |~ |~ | |two.c===============one.c=============| | | +--------------------------------------+
:vertical newThe ":vertical" command can be inserted before another command that splits a window. This will cause that command to split the window vertically instead of horizontally. (If the command doesn't split a window, it works unmodified.)
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 rightCTRL-W
t move to the TOP window
CTRL-W
b move to the BOTTOM window08.5
Moving windows+----------------------------------+ |/* file two.c */ | |~ | |~ | |two.c=============================| |/* file three.c */ | |~ | |~ | |three.c===========================| |/* file one.c */ | |~ | |one.c=============================| | | +----------------------------------+
CTRL-W
w)
and then type this command:CTRL-W KThis 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========| | | +-------------------------------------------+
CTRL-W
K in the middle window (three.c) will result in:
+-------------------------------------------+ |/* three.c */ | |~ | |~ | |three.c====================================| |/* two.c */ |/* one.c */ | |~ |~ | |two.c==================one.c===============| | | +-------------------------------------------+
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 right08.6
Commands for all windows:qallThis 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.
:wallThis 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:
:wqallThis 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!
vim -o one.txt two.txt three.txtThis results in:
+-------------------------------+ |file one.txt | |~ | |one.txt========================| |file two.txt | |~ | |two.txt========================| |file three.txt | |~ | |three.txt======================| | | +-------------------------------+
08.7
Viewing differences with diff modenvim -d main.c~ main.cVim will start, with two windows side by side. You will only see the line in which you added characters, and a few lines above and below it.
VV VV +-----------------------------------------+ |+ +--123 lines: /* a|+ +--123 lines: /* a| <- fold | text | text | | text | text | | text | text | | text | changed text | <- changed line | text | text | | text | ------------------| <- deleted line | text | text | | text | text | | text | text | |+ +--432 lines: text|+ +--432 lines: text| <- fold | ~ | ~ | | ~ | ~ | |main.c~==============main.c==============| | | +-----------------------------------------+
:edit main.c :vertical diffsplit main.c~The ":vertical" command is used to make the window split vertically. If you omit this, you will get a horizontal split.
:edit main.c :vertical diffpatch main.c.diffWARNING: The patch file must contain only one patch, for the file you are editing. Otherwise you will get a lot of error messages, and some files might be patched unexpectedly. The patching will only be done to the copy of the file in Vim. The file on your harddisk will remain unmodified (until you decide to write the file).
:set noscrollbind
]cTo go the other way use:
[cPrepended a count to jump further away.
:diffupdateTo remove a difference, you can move the text in a highlighted block from one window to another. Take the "main.c" and "main.c~" example above. Move the cursor to the left window, on the line that was deleted in the other window. Now type this command:
dpThe change will be removed by putting the text of the current window in the other window. "dp" stands for "diff put". You can also do it the other way around. Move the cursor to the right window, to the line where "changed" was inserted. Now type this command:
doThe change will now be removed by getting the text from the other window. Since there are no changes left now, Vim puts all text in a closed fold. "do" stands for "diff obtain". "dg" would have been better, but that already has a different meaning ("dgg" deletes from the cursor until the first line).
08.8
VariousCTRL-W
is prepended. CTRL-^
jumps to the
alternate file, CTRL-W
CTRL-^
splits the window and edits the alternate file.{cmd}
left or above the current window
:aboveleft {cmd}
idem
:rightbelow {cmd}
right or below the current window
:belowright {cmd}
idem
:topleft {cmd}
at the top or left of the Vim window
:botright {cmd}
at the bottom or right of the Vim window08.9
Tab pages:tabedit thatfileThis will edit the file "thatfile" in a window that occupies the whole Vim window. And you will notice a bar at the top with the two file names:
+----------------------------------+ | thisfile | /thatfile/ __________X| (thatfile is bold) |/* thatfile */ | |that | |that | |~ | |~ | |~ | | | +----------------------------------+
+----------------------------------+ | /thisfile/ | thatfile __________X| (thisfile is bold) |/* thisfile */ | |this | |this | |~ | |~ | |~ | | | +----------------------------------+
:tab splitThis makes a new tab page with one window that is editing the same buffer as the window we were in:
+-------------------------------------+ | thisfile | /thisfile/ | thatfile __X| (thisfile is bold) |/* thisfile */ | |this | |this | |~ | |~ | |~ | | | +-------------------------------------+
:tab help gtWill show the help text for "gt" in a new tab page.