usr_08.txt ForVim version 9.2. Last change: 2026 Feb 14 VIM USER MANUALbyBramMoolenaar SplittingwindowsDisplay two different files above each other. Orview two locations in thefileat the same time. See the difference between two files by putting themside by side. All thisis possible with split windows.08.1 Splitawindow08.2 Splitawindow on another file08.3 Window size08.4 Vertical splits08.5 Movingwindows08.6 Commands for allwindows08.7 Viewing differences withvimdiff08.8 Various08.9Tab pages Next chapter:usr_09.txt Using theGUI Previous chapter:usr_07.txt Editing more than one fileTable of contents:usr_toc.txt==============================================================================08.1 SplitawindowThe easiest way to opena newwindowis to use the following command::splitThis command splits the screen into twowindows and leaves the cursor in thetop one:+----------------------------------+|/* file one.c */ ||~ ||~ |one.c=============================|/* file one.c */ ||~ |one.c=============================| |+----------------------------------+What you see hereis twowindows on the same file. The line with "===="isthe status line. It displays information about thewindow above it. (Inpractice the status line will be in reverse video.) The twowindows allow you toview two parts of the same file. For example,you could make the topwindow show the variable declarations ofa program, andthe bottom one the code that uses these variables.TheCTRL-Ww command can be used to jump between the windows. If you are inthe top window,CTRL-Ww jumps to thewindow below it. If you are in thebottomwindowit will jump to the first window. (CTRL-WCTRL-W does the samething, incase you letgo of the CTRL keya bit later.)CLOSE THE WINDOWTo closea window, use the command::closeActually, any command that quits editinga file works, like ":quit" and "ZZ".But ":close" prevents you from accidentallyexiting Vim when you close thelast window.CLOSING ALL OTHER WINDOWSIf you have openeda whole bunch of windows, but now want to concentrate onone of them, this command will be useful::onlyThis closes all windows, except for the current one. If any of the otherwindows has changes, you will get an error message and thatwindow won't beclosed.==============================================================================08.2 Splitawindow on another fileThe following command opensa secondwindow and starts editing the given 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=============================| |+----------------------------------+To openawindow ona new, empty file, use this::newYou can repeat the ":split" and ":new" commands to createas manywindowsasyou like.==============================================================================08.3 Window sizeThe ":split" command can takea number argument. If specified, this will bethe height of the new window. For example, the following opensa newwindowthree lines high and starts editing the file alpha.c::3split alpha.cFor existingwindows you can change the size in several ways. When you haveaworking mouse,itis easy: Move the mouse pointer to the status line thatseparates two windows, and dragit up or down.To increase the size ofa window:CTRL-W +To decrease it:CTRL-W -Both of these commands takeacount and increase or decrease thewindow sizeby that many lines. Thus "4CTRL-W+" make thewindow four lines higher.To set thewindow height toa specified number of lines:{height}CTRL-W _That's:a number{height},CTRL-W and then an underscore (the- key with Shifton English-US keyboards). To makeawindowas highasit can be, use theCTRL-W_ command withoutacount.USING THE MOUSEIn Vim you cando many things very quickly from the keyboard. Unfortunately,thewindow resizing commands require quitea bit of typing. In this case,using the mouseis faster. Position the mouse pointer ona status line. Nowpress the left mouse button and drag. The status line will move, thus makingthewindow on one side higher and the other smaller.OPTIONSThe'winheight' option can be set toa minimal desired height ofawindow and'winminheight' toa hard minimum height. Likewise, thereis'winwidth' for the minimal desired width and'winminwidth' for the hard minimum width. The'equalalways' option, when set, makes Vim equalize thewindows sizeswhenawindowis closed or opened.==============================================================================08.4 Vertical splitsThe ":split" command creates the newwindow above the current one. To makethewindow appearat the left side, use::vsplitor::vsplit two.cThe result looks something like this:+--------------------------------------+|/* file two.c */ |/* file one.c */ ||~ |~ ||~ |~ ||~ |~ |two.c===============one.c=============| |+--------------------------------------+Actually, the | lines in the middle will be in reverse video. Thisis calledthe vertical separator. It separates the twowindows left and right of it.Thereis also the ":vnew" command, to opena vertically splitwindow ona new,empty file. Another way todo this::vertical newThe ":vertical" command can be inserted before another command that splitsawindow. This will cause that command to split thewindow vertically insteadof horizontally. (If the command doesn't splita window,it worksunmodified.)MOVING BETWEEN WINDOWSSince you can splitwindows horizontally and verticallyas muchas you like,you can create almost any layout of windows. Then you can use these commandsto move between them:CTRL-Whmove to thewindow on the leftCTRL-Wjmove to thewindow belowCTRL-Wkmove to thewindow aboveCTRL-Wlmove to thewindow on the rightCTRL-Wtmove to the TOPwindowCTRL-Wbmove to the BOTTOMwindowYou will notice the same lettersas used for moving the cursor. And thecursor keys can also be used, if you like. More commands to move to other windows:Q_wi.==============================================================================08.5 MovingwindowsYou have splita few windows, but now they are in the wrong place. Then youneeda command to move thewindow somewhere else. For example, you have threewindows like this:+----------------------------------+|/* file two.c */ ||~ ||~ |two.c=============================|/* file three.c */ ||~ ||~ |three.c===========================|/* file one.c */ ||~ |one.c=============================| |+----------------------------------+Clearly the last one should beat the top. Go to thatwindow (usingCTRL-W w)and then type this command:CTRL-W KThis uses theuppercaseletter K. What happensis that thewindowis moved tothe very top. You will notice thatKis again used for moving upwards. When you have vertical splits,CTRL-WK will move the currentwindow to thetop and makeit occupy the full width of the Vim window. If thisis yourlayout:+-------------------------------------------+|/* two.c */ |/* three.c */ |/* one.c */ ||~ |~ |~ ||~ |~ |~ ||~ |~ |~ ||~ |~ |~ ||~ |~ |~ |two.c=========three.c=========one.c========| |+-------------------------------------------+Then usingCTRL-WK in the middlewindow (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-WHmovewindow to the far leftCTRL-WJmovewindow to the bottomCTRL-WLmovewindow to the far right==============================================================================08.6 Commands for allwindowsWhen you have severalwindows open and you want to quit Vim, you can closeeachwindow separately.A quicker wayis using this command::qallThis stands for "quit all". If any of thewindows contain changes, Vim willnot exit. The cursor will automatically be positioned inawindow withchanges. You can then either use ":write" to save the changes, or ":quit!" tothrow them away.If you know there arewindows with changes, and you want to save all thesechanges, use this command::wallThis stands for "write all". But actually,it only writes files withchanges. Vim knowsit doesn't make sense to write files that were notchanged. And then thereis the combination of ":qall" and ":wall": the "write andquit all" command::wqallThis writes all modified files and quits Vim. Finally, thereisa command that quits Vim and throws away all changes::qall!Be careful, thereis no way toundo this command!OPENING A WINDOW FOR ALL ARGUMENTSTo make Vim openawindow for each file, startit with the "-o" argument: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======================||+-------------------------------+The "-O" argumentis used to get vertically split windows. When Vimis already running, the ":all" command opensawindow for eachfile in the argument list. ":vertical all" doesit with vertical splits.==============================================================================08.7 Viewing differences withvimdiffThereisa special way to start Vim, which shows the differences between twofiles. Let's takea file "main.c" andinserta few characters in one line.Write this file with the'backup' option set, so that thebackup file"main.c~" will contain the previous version of the file. Type this command ina shell (not in Vim):vimdiff main.c~ main.cVim will start, with twowindows side by side. You will only see the linein which you added characters, anda 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==============| |+-----------------------------------------+(This picture doesn't show the highlighting, use thevimdiff command forabetter look.)The lines that were not modified have been collapsed into one line. Thisiscalleda closed fold. They are indicated in the picture with "<- fold". Thusthe single fold lineat the top stands for 123 text lines. These lines areequal in both files. The line marked with "<- changed line"is highlighted, and the insertedtextis displayed with another color. This clearly shows what the differenceis between the two files. The line that was deletedis displayed with "---" in the main.c window.See the "<- deleted line" marker in the picture. These characters are notreally there. They just fill up main.c, so thatit displays the same numberof linesas the other window.THE FOLD COLUMNEachwindow hasa column on the left witha slightly different background. Inthe picture above these are indicated with "VV". You notice thereisa pluscharacter there, in front of each closed fold. Move the mouse pointer to thatplus and click the left button. The fold will open, and you can see the textthatit contains. The fold column containsa minus sign for an open fold. If you click onthis -, the fold will close. Obviously, this only works when you havea working mouse. You can also use"zo" to opena fold and "zc" to close it.DIFFING IN VIMAnother way to start indiff mode can be done from inside Vim. Edit the"main.c" file, then makea split and show the differences::edit main.c:vertical diffsplit main.c~The ":vertical" commandis used to make thewindow split vertically. If youomit this, you will geta horizontal split.If you havea patch ordiff file, you can use the third way to startdiffmode. First edit the file to which the patch applies. Then tell Vim the nameof the patch file::edit main.c:vertical diffpatch main.c.diffWARNING: The patch filemust contain only one patch, for the file you areediting. Otherwise you will geta lot of error messages, and some files mightbe patched unexpectedly. The patching will only be done to the copy of the file in Vim. The file onyour harddisk will remain unmodified (until you decide to write the file).SCROLL BINDINGWhen the files have more changes, you can scroll in the usual way. Vim willtry to keep both thewindows startat the same position, so you can easily seethe differences side by side. When you don't want this fora moment, use this command::set noscrollbindJUMPING TO CHANGESWhen you have disabledfolding in some way,it may be difficult to find thechanges. Use this command to jump forward to the next change:]cTogo the other way use:[cPrependacount to jump further away. Thus "4]c" jumps to the fourth nextchange, and "3[c" jumps to the third previous change.REMOVING CHANGESYou can move text from onewindow to the other. This either removesdifferences or adds new ones. Vim doesn't keep the highlighting updated inall situations. To updateit use this command::diffupdateTo removea difference, you can move the text ina highlighted block from onewindow to another. Take the "main.c" and "main.c~" example above. Move thecursor 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 currentwindow in theother window. "dp" stands for "diffput". You can alsodoit the other way around. Move the cursor to the rightwindow, 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 ina closed fold."do" stands for "diff obtain". "dg" would have been better, but that alreadyhasa different meaning("dgg" deletes from the cursor until the first line).For details aboutdiff mode, seevimdiff.==============================================================================08.8 VariousThe'laststatus' option can be used to specify when the lastwindow hasastatusline:0never1only when there are splitwindows (the default)2alwaysMany commands that edit another file havea variant that splits the window.ForCommand-line commands thisis done by prepending an "s". For example:":tag" jumps toa tag, ":stag" splits thewindow and jumps toatag. ForNormal mode commandsaCTRL-Wis prepended.CTRL-^ jumps to thealternate file,CTRL-WCTRL-^ splits thewindow and edits the alternate file.The'splitbelow' option can be set to makea newwindow appear below thecurrent window. The'splitright' option can be set to makea vertically splitwindow appear right of the current window.When splittingawindow you can prependa modifier command to tell where thewindowis to appear::leftabove{cmd}left or above the currentwindow:aboveleft{cmd}idem:rightbelow{cmd}right or below the currentwindow:belowright{cmd}idem:topleft{cmd}at the top or left of the Vimwindow:botright{cmd}at the bottom or right of the Vimwindow==============================================================================08.9Tab pagesYou will have noticed thatwindows never overlap. That means you quickly runout of screen space. The solution for thisis calledTab pages.Assume you are editing "thisfile". To createa newtab page use this command::tabedit thatfileThis will edit the file "thatfile" inawindow that occupies the whole Vimwindow. And you will noticeabarat the top with the two file names:+----------------------------------+| thisfile | /thatfile/ __________X| (thatfileis bold)|/* thatfile */ ||that ||that ||~ ||~ ||~ || |+----------------------------------+You now have twotab pages. The first one hasawindow for "thisfile" and thesecond oneawindow for "thatfile". It's like two pages that are on top ofeach other, withatab sticking out of each page showing the file name.Now use the mouse to click on "thisfile" in the top line. The resultis+----------------------------------+| /thisfile/ | thatfile __________X| (thisfileis bold)|/* thisfile */ ||this ||this ||~ ||~ ||~ || |+----------------------------------+Thus you can switch betweentab pages by clicking on the label in the topline. If you don't havea mouse or don't want to use it, you can use the "gt"command. Mnemonic: Goto Tab.Now let's create anothertab page with the command::tab splitThis makesa newtab page with onewindow thatis editing the same bufferasthewindow we were in:+-------------------------------------+| thisfile | /thisfile/ | thatfile __X| (thisfileis bold)|/* thisfile */ ||this ||this ||~ ||~ ||~ || |+-------------------------------------+You canput ":tab" before anyEx command that opensa window. Thewindow willbe opened ina newtab page. Another example::tab help gtWill show thehelp text for "gt" ina newtab page.A few more things you cando withtab pages:- click with the mouse in thespace after the last labelThe nexttab page will be selected, like with "gt".- click with the mouse on the "X" in the top right cornerThe currenttab page will be closed. Unless there are unsavedchanges in the currenttab page.- double click with the mouse in the top lineA newtab page will be created.- the "tabonly" commandCloses alltab pages except the current one. Unless there are unsavedchanges in othertab pages.For more information abouttab pages seetab-page.==============================================================================Next chapter:usr_09.txt Using theGUICopyright: seemanual-copyright vim:tw=78:ts=8:noet:ft=help:norl: