robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Eisuke Kawashimadocs: adjust modelines for HTML rendering #396497e778205ab

master
19.0 KiB607 linesraw
1*usr_08.txt*	Nvim
2
3
4		     VIM USER MANUAL	by Bram Moolenaar
5
6
7			      Splitting windows
8
9
10Display two different files above each other.  Or view two locations in the
11file at the same time.  See the difference between two files by putting them
12side by side.  All this is possible with split windows.
13
14|08.1|	Split a window
15|08.2|	Split a window on another file
16|08.3|	Window size
17|08.4|	Vertical splits
18|08.5|	Moving windows
19|08.6|	Commands for all windows
20|08.7|	Viewing differences with diff mode
21|08.8|	Various
22|08.9|	Tabpages
23
24     Next chapter: |usr_09.txt|  Using the GUI
25 Previous chapter: |usr_07.txt|  Editing more than one file
26Table of contents: |usr_toc.txt|
27
28==============================================================================
29*08.1*	Split a window
30
31The easiest way to open a new window is to use the following command: >
32
33	:split
34
35This command splits the screen into two windows and leaves the cursor in the
36top one:
37>
38	+----------------------------------+
39	|/* file one.c */		   |
40	|~				   |
41	|~				   |
42	|one.c=============================|
43	|/* file one.c */		   |
44	|~				   |
45	|one.c=============================|
46	|				   |
47	+----------------------------------+
48<
49What you see here is two windows on the same file.  The line with "====" is
50the status line.  It displays information about the window above it.  (In
51practice the status line will be in reverse video.)
52   The two windows allow you to view two parts of the same file.  For example,
53you could make the top window show the variable declarations of a program, and
54the bottom one the code that uses these variables.
55
56The CTRL-W w command can be used to jump between the windows.  If you are in
57the top window, CTRL-W w jumps to the window below it.  If you are in the
58bottom window it will jump to the first window.  (CTRL-W CTRL-W does the same
59thing, in case you let go of the CTRL key a bit later.)
60
61
62CLOSE THE WINDOW
63
64To close a window, use the command: >
65
66	:close
67
68Actually, any command that quits editing a file works, like ":quit" and "ZZ".
69But ":close" prevents you from accidentally exiting Vim when you close the
70last window.
71
72
73CLOSING ALL OTHER WINDOWS
74
75If you have opened a whole bunch of windows, but now want to concentrate on
76one of them, this command will be useful: >
77
78	:only
79
80This closes all windows, except for the current one.  If any of the other
81windows has changes, you will get an error message and that window won't be
82closed.
83
84==============================================================================
85*08.2*	Split a window on another file
86
87The following command opens a second window and starts editing the given file:
88>
89	:split two.c
90
91If you were editing one.c, then the result looks like this:
92>
93	+----------------------------------+
94	|/* file two.c */		   |
95	|~				   |
96	|~				   |
97	|two.c=============================|
98	|/* file one.c */		   |
99	|~				   |
100	|one.c=============================|
101	|				   |
102	+----------------------------------+
103<
104To open a window on a new, empty file, use this: >
105
106	:new
107
108You can repeat the ":split" and ":new" commands to create as many windows as
109you like.
110
111==============================================================================
112*08.3*	Window size
113
114The ":split" command can take a number argument.  If specified, this will be
115the height of the new window.  For example, the following opens a new window
116three lines high and starts editing the file alpha.c: >
117
118	:3split alpha.c
119
120For existing windows you can change the size in several ways.  When you have a
121working mouse, it is easy: Move the mouse pointer to the status line that
122separates two windows, and drag it up or down.
123
124To increase the size of a window: >
125
126	CTRL-W +
127
128To decrease it: >
129
130	CTRL-W -
131
132Both of these commands take a count and increase or decrease the window size
133by that many lines.  Thus "4 CTRL-W +" make the window four lines higher.
134
135To set the window height to a specified number of lines: >
136
137	{height}CTRL-W _
138
139That's: a number {height}, CTRL-W and then an underscore (the - key with Shift
140on English-US keyboards).
141   To make a window as high as it can be, use the CTRL-W _ command without a
142count.
143
144
145USING THE MOUSE
146
147In Vim you can do many things very quickly from the keyboard.  Unfortunately,
148the window resizing commands require quite a bit of typing.  In this case,
149using the mouse is faster.  Position the mouse pointer on a status line.  Now
150press the left mouse button and drag.  The status line will move, thus making
151the window on one side higher and the other smaller.
152
153
154OPTIONS
155
156The 'winheight' option can be set to a minimal desired height of a window and
157'winminheight' to a hard minimum height.
158   Likewise, there is 'winwidth' for the minimal desired width and
159'winminwidth' for the hard minimum width.
160   The 'equalalways' option, when set, makes Vim equalize the windows sizes
161when a window is closed or opened.
162
163==============================================================================
164*08.4*	Vertical splits
165
166The ":split" command creates the new window above the current one.  To make
167the window appear at the left side, use: >
168
169	:vsplit
170
171or: >
172	:vsplit two.c
173
174The result looks something like this:
175>
176	+--------------------------------------+
177	|/* file two.c */   |/* file one.c */  |
178	|~		    |~		       |
179	|~		    |~		       |
180	|~		    |~		       |
181	|two.c===============one.c=============|
182	|				       |
183	+--------------------------------------+
184<
185Actually, the | lines in the middle will be in reverse video.  This is called
186the vertical separator.  It separates the two windows left and right of it.
187
188There is also the ":vnew" command, to open a vertically split window on a new,
189empty file.  Another way to do this: >
190
191	:vertical new
192
193The ":vertical" command can be inserted before another command that splits a
194window.  This will cause that command to split the window vertically instead
195of horizontally.  (If the command doesn't split a window, it works
196unmodified.)
197
198
199MOVING BETWEEN WINDOWS
200
201Since you can split windows horizontally and vertically as much as you like,
202you can create almost any layout of windows.  Then you can use these commands
203to move between them:
204
205	CTRL-W h	move to the window on the left
206	CTRL-W j	move to the window below
207	CTRL-W k	move to the window above
208	CTRL-W l	move to the window on the right
209
210	CTRL-W t	move to the TOP window
211	CTRL-W b	move to the BOTTOM window
212
213You will notice the same letters as used for moving the cursor.  And the
214cursor keys can also be used, if you like.
215   More commands to move to other windows: |Q_wi|.
216
217==============================================================================
218*08.5*	Moving windows
219
220You have split a few windows, but now they are in the wrong place.  Then you
221need a command to move the window somewhere else.  For example, you have three
222windows like this:
223>
224	+----------------------------------+
225	|/* file two.c */		   |
226	|~				   |
227	|~				   |
228	|two.c=============================|
229	|/* file three.c */		   |
230	|~				   |
231	|~				   |
232	|three.c===========================|
233	|/* file one.c */		   |
234	|~				   |
235	|one.c=============================|
236	|				   |
237	+----------------------------------+
238<
239Clearly the last one should be at the top.  Go to that window (using CTRL-W w)
240and then type this command: >
241
242	CTRL-W K
243
244This uses the uppercase letter K.  What happens is that the window is moved to
245the very top.  You will notice that K is again used for moving upwards.
246   When you have vertical splits, CTRL-W K will move the current window to the
247top and make it occupy the full width of the Vim window.  If this is your
248layout:
249>
250	+-------------------------------------------+
251	|/* two.c */  |/* three.c */  |/* one.c */  |
252	|~	      |~	      |~	    |
253	|~	      |~	      |~	    |
254	|~	      |~	      |~	    |
255	|~	      |~	      |~	    |
256	|~	      |~	      |~	    |
257	|two.c=========three.c=========one.c========|
258	|					    |
259	+-------------------------------------------+
260<
261Then using CTRL-W K in the middle window (three.c) will result in:
262>
263	+-------------------------------------------+
264	|/* three.c */				    |
265	|~					    |
266	|~					    |
267	|three.c====================================|
268	|/* two.c */	       |/* one.c */	    |
269	|~		       |~		    |
270	|two.c==================one.c===============|
271	|					    |
272	+-------------------------------------------+
273<
274The other three similar commands (you can probably guess these now):
275
276	CTRL-W H	move window to the far left
277	CTRL-W J	move window to the bottom
278	CTRL-W L	move window to the far right
279
280==============================================================================
281*08.6*	Commands for all windows
282
283When you have several windows open and you want to quit Vim, you can close
284each window separately.  A quicker way is using this command: >
285
286	:qall
287
288This stands for "quit all".  If any of the windows contain changes, Vim will
289not exit.  The cursor will automatically be positioned in a window with
290changes.  You can then either use ":write" to save the changes, or ":quit!" to
291throw them away.
292
293If you know there are windows with changes, and you want to save all these
294changes, use this command: >
295
296	:wall
297
298This stands for "write all".  But actually, it only writes files with
299changes.  Vim knows it doesn't make sense to write files that were not
300changed.
301   And then there is the combination of ":qall" and ":wall": the "write and
302quit all" command: >
303
304	:wqall
305
306This writes all modified files and quits Vim.
307   Finally, there is a command that quits Vim and throws away all changes: >
308
309	:qall!
310
311Be careful, there is no way to undo this command!
312
313
314OPENING A WINDOW FOR ALL ARGUMENTS
315
316To make Vim open a window for each file, start it with the "-o" argument: >
317
318	vim -o one.txt two.txt three.txt
319
320This results in:
321>
322	+-------------------------------+
323	|file one.txt			|
324	|~				|
325	|one.txt========================|
326	|file two.txt			|
327	|~				|
328	|two.txt========================|
329	|file three.txt			|
330	|~				|
331	|three.txt======================|
332	|				|
333	+-------------------------------+
334<
335The "-O" argument is used to get vertically split windows.
336   When Vim is already running, the ":all" command opens a window for each
337file in the argument list.  ":vertical all" does it with vertical splits.
338
339==============================================================================
340*08.7*	Viewing differences with diff mode
341
342There is a special way to start Nvim, which shows the differences between two
343files.  Let's take a file "main.c" and insert a few characters in one line.
344Write this file with the 'backup' option set, so that the backup file
345"main.c~" will contain the previous version of the file.
346Type this command in a shell to start Nvim in diff mode: >
347
348	nvim -d main.c~ main.c
349
350Vim will start, with two windows side by side.  You will only see the line
351in which you added characters, and a few lines above and below it.
352>
353	 VV		      VV
354	+-----------------------------------------+
355	|+ +--123 lines: /* a|+ +--123 lines: /* a|  <- fold
356	|  text		     |	text		  |
357	|  text		     |	text		  |
358	|  text		     |	text		  |
359	|  text		     |	changed text	  |  <- changed line
360	|  text		     |	text		  |
361	|  text		     |	------------------|  <- deleted line
362	|  text		     |	text		  |
363	|  text		     |	text		  |
364	|  text		     |	text		  |
365	|+ +--432 lines: text|+ +--432 lines: text|  <- fold
366	|  ~		     |	~		  |
367	|  ~		     |	~		  |
368	|main.c~==============main.c==============|
369	|					  |
370	+-----------------------------------------+
371<
372(This picture doesn't show the highlighting, use "nvim -d" for that.)
373
374The lines that were not modified have been collapsed into one line.  This is
375called a closed fold.  They are indicated in the picture with "<- fold".  Thus
376the single fold line at the top stands for 123 text lines.  These lines are
377equal in both files.
378   The line marked with "<- changed line" is highlighted, and the inserted
379text is displayed with another color.  This clearly shows what the difference
380is between the two files.
381   The line that was deleted is displayed with "---" in the main.c window.
382See the "<- deleted line" marker in the picture.  These characters are not
383really there.  They just fill up main.c, so that it displays the same number
384of lines as the other window.
385
386
387THE FOLD COLUMN
388
389Each window has a column on the left with a slightly different background.  In
390the picture above these are indicated with "VV".  You notice there is a plus
391character there, in front of each closed fold.  Move the mouse pointer to that
392plus and click the left button.  The fold will open, and you can see the text
393that it contains.
394   The fold column contains a minus sign for an open fold.  If you click on
395this -, the fold will close.
396   Obviously, this only works when you have a working mouse.  You can also use
397"zo" to open a fold and "zc" to close it.
398
399
400DIFFING IN VIM
401
402Another way to start in diff mode can be done from inside Vim.  Edit the
403"main.c" file, then make a split and show the differences: >
404
405	:edit main.c
406	:vertical diffsplit main.c~
407
408The ":vertical" command is used to make the window split vertically.  If you
409omit this, you will get a horizontal split.
410
411If you have a patch or diff file, you can use the third way to start diff
412mode.  First edit the file to which the patch applies.  Then tell Vim the name
413of the patch file: >
414
415	:edit main.c
416	:vertical diffpatch main.c.diff
417
418WARNING: The patch file must contain only one patch, for the file you are
419editing.  Otherwise you will get a lot of error messages, and some files might
420be patched unexpectedly.
421   The patching will only be done to the copy of the file in Vim.  The file on
422your harddisk will remain unmodified (until you decide to write the file).
423
424
425SCROLL BINDING
426
427When the files have more changes, you can scroll in the usual way.  Vim will
428try to keep both the windows start at the same position, so you can easily see
429the differences side by side.
430   When you don't want this for a moment, use this command: >
431
432	:set noscrollbind
433
434
435JUMPING TO CHANGES
436
437When you have disabled folding in some way, it may be difficult to find the
438changes.  Use this command to jump forward to the next change: >
439
440	]c
441
442To go the other way use: >
443
444	[c
445
446Prepend a count to jump further away. Thus "4]c" jumps to the fourth next
447change, and "3[c" jumps to the third previous change.
448
449
450REMOVING CHANGES
451
452You can move text from one window to the other.  This either removes
453differences or adds new ones.  Vim doesn't keep the highlighting updated in
454all situations.  To update it use this command: >
455
456	:diffupdate
457
458To remove a difference, you can move the text in a highlighted block from one
459window to another.  Take the "main.c" and "main.c~" example above.  Move the
460cursor to the left window, on the line that was deleted in the other window.
461Now type this command: >
462
463	dp
464
465The change will be removed by putting the text of the current window in the
466other window.  "dp" stands for "diff put".
467   You can also do it the other way around.  Move the cursor to the right
468window, to the line where "changed" was inserted.  Now type this command: >
469
470	do
471
472The change will now be removed by getting the text from the other window.
473Since there are no changes left now, Vim puts all text in a closed fold.
474"do" stands for "diff obtain".  "dg" would have been better, but that already
475has a different meaning ("dgg" deletes from the cursor until the first line).
476
477For details about diff mode, see |diff-mode|.
478
479==============================================================================
480*08.8*	Various
481
482The 'laststatus' option can be used to specify when the last window has a
483statusline:
484
485	0	never
486	1	only when there are split windows (the default)
487	2	always
488	3	have a global statusline at the bottom instead of one for each
489		window
490
491Many commands that edit another file have a variant that splits the window.
492For Command-line commands this is done by prepending an "s".  For example:
493":tag" jumps to a tag, ":stag" splits the window and jumps to a
494tag.
495   For Normal mode commands a CTRL-W is prepended.  CTRL-^ jumps to the
496alternate file, CTRL-W CTRL-^ splits the window and edits the alternate file.
497
498The 'splitbelow' option can be set to make a new window appear below the
499current window.  The 'splitright' option can be set to make a vertically split
500window appear right of the current window.
501
502When splitting a window you can prepend a modifier command to tell where the
503window is to appear:
504
505	:leftabove {cmd}	left or above the current window
506	:aboveleft {cmd}	idem
507	:rightbelow {cmd}	right or below the current window
508	:belowright {cmd}	idem
509	:topleft {cmd}		at the top or left of the Vim window
510	:botright {cmd}		at the bottom or right of the Vim window
511
512
513==============================================================================
514*08.9*	Tabpages
515
516You will have noticed that windows never overlap.  That means you quickly run
517out of screen space.  The solution for this is called Tabpages.
518
519Assume you are editing "thisfile".  To create a new tabpage use this command: >
520
521	:tabedit thatfile
522
523This will edit the file "thatfile" in a window that occupies the whole Vim
524window.  And you will notice a bar at the top with the two file names:
525>
526	+----------------------------------+
527	| thisfile | /thatfile/ __________X|    (thatfile is bold)
528	|/* thatfile */			   |
529	|that				   |
530	|that				   |
531	|~				   |
532	|~				   |
533	|~				   |
534	|				   |
535	+----------------------------------+
536<
537You now have two tabpages.  The first one has a window for "thisfile" and the
538second one a window for "thatfile".  It's like two pages that are on top of
539each other, with a tab sticking out of each page showing the file name.
540
541Now use the mouse to click on "thisfile" in the top line.  The result is
542>
543	+----------------------------------+
544	| /thisfile/ | thatfile __________X|    (thisfile is bold)
545	|/* thisfile */			   |
546	|this				   |
547	|this				   |
548	|~				   |
549	|~				   |
550	|~				   |
551	|				   |
552	+----------------------------------+
553<
554Thus you can switch between tabpages by clicking on the label in the top
555line.  If you don't have a mouse or don't want to use it, you can use the "gt"
556command.  Mnemonic: Goto Tab.
557
558Now let's create another tabpage with the command: >
559
560	:tab split
561
562This makes a new tabpage with one window that is editing the same buffer as
563the window we were in:
564>
565	+-------------------------------------+
566	| thisfile | /thisfile/ | thatfile __X|   (thisfile is bold)
567	|/* thisfile */			      |
568	|this				      |
569	|this				      |
570	|~				      |
571	|~				      |
572	|~				      |
573	|				      |
574	+-------------------------------------+
575<
576You can put ":tab" before any Ex command that opens a window.  The window will
577be opened in a new tabpage.  Another example: >
578
579	:tab help gt
580
581Will show the help text for "gt" in a new tabpage.
582
583A few more things you can do with tabpages:
584
585- click with the mouse in the space after the last label
586	The next tabpage will be selected, like with "gt".
587
588- click with the mouse on the "X" in the top right corner
589	The current tabpage will be closed.  Unless there are unsaved
590	changes in the current tabpage.
591
592- double click with the mouse in the top line
593	A new tabpage will be created.
594
595- the "tabonly" command
596	Closes all tabpages except the current one.  Unless there are unsaved
597	changes in other tabpages.
598
599For more information about tabpages see |tabpage|.
600
601==============================================================================
602
603Next chapter: |usr_09.txt|  Using the GUI
604
605Copyright: see |manual-copyright|
606
607vim:tw=78:ts=8:noet:ft=help:norl: