1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
|
*windows.txt* For Vim version 7.0aa. Last change: 2006 Jan 19
VIM REFERENCE MANUAL by Bram Moolenaar
Editing with multiple windows and buffers. *windows* *buffers*
The commands which have been added to use multiple windows and buffers are
explained here. Additionally, there are explanations for commands that work
differently when used in combination with more than one window.
The basics are explained in chapter 7 and 8 of the user manual |usr_07.txt|
|usr_08.txt|.
1. Introduction |windows-intro|
2. Starting Vim |windows-starting|
3. Opening and closing a window |opening-window|
4. Moving cursor to other windows |window-move-cursor|
5. Moving windows around |window-moving|
6. Window resizing |window-resize|
7. Argument and buffer list commands |buffer-list|
8. Do a command in all buffers or windows |list-repeat|
9. Tag or file name under the cursor |window-tag|
10. The preview window |preview-window|
11. Using hidden buffers |buffer-hidden|
12. Special kinds of buffers |special-buffers|
{Vi does not have any of these commands}
{not able to use multiple windows when the |+windows| feature was disabled at
compile time}
{not able to use vertically split windows when the |+vertsplit| feature was
disabled at compile time}
==============================================================================
1. Introduction *windows-intro*
A window is a viewport onto a buffer. You can use multiple windows on one
buffer, or several windows on different buffers.
A buffer is a file loaded into memory for editing. The original file remains
unchanged until you write the buffer to the file.
A buffer can be in one of three states:
*active-buffer*
active: The buffer is displayed in a window. If there is a file for this
buffer, it has been read into the buffer. The buffer may have been
modified since then and thus be different from the file.
*hidden-buffer*
hidden: The buffer is not displayed. If there is a file for this buffer, it
has been read into the buffer. Otherwise it's the same as an active
buffer, you just can't see it.
*inactive-buffer*
inactive: The buffer is not displayed and does not contain anything. Options
for the buffer are remembered if the file was once loaded. It can
contain marks from the |viminfo| file. But the buffer doesn't
contain text.
In a table:
state displayed loaded ":buffers" ~
in window shows ~
active yes yes 'a'
hidden no yes 'h'
inactive no no ' '
Note: All CTRL-W commands can also be executed with |:wincmd|, for those
places where a Normal mode command can't be used or is inconvenient.
==============================================================================
2. Starting Vim *windows-starting*
By default, Vim starts with one window, just like Vi.
The "-o" and "-O" arguments to Vim can be used to open a window for each file
in the argument list. The "-o" argument will split the windows horizontally;
the "-O" argument will split the windows vertically. If both "-o" and "-O"
are given, the last one encountered will be used to determine the split
orientation. For example, this will open three windows, split horizontally: >
vim -o file1 file2 file3
"-oN", where N is a decimal number, opens N windows split horizontally. If
there are more file names than windows, only N windows are opened and some
files do not get a window. If there are more windows than file names, the
last few windows will be editing empty buffers. Similarly, "-ON" opens N
windows split vertically, with the same restrictions.
If there are many file names, the windows will become very small. You might
want to set the 'winheight' and/or 'winwidth' options to create a workable
situation.
Buf/Win Enter/Leave |autocommand|s are not executed when opening the new
windows and reading the files, that's only done when they are really entered.
*status-line*
A status line will be used to separate windows. The 'laststatus' option tells
when the last window also has a status line:
'laststatus' = 0 never a status line
'laststatus' = 1 status line if there is more than one window
'laststatus' = 2 always a status line
You can change the contents of the status line with the 'statusline' option.
This option can be local to the window, so that you can have a different
status line in each window.
Normally, inversion is used to display the status line. This can be changed
with the 's' character in the 'highlight' option. For example, "sb" sets it to
bold characters. If no highlighting is used for the status line ("sn"), the
'^' character is used for the current window, and '=' for other windows. If
the mouse is supported and enabled with the 'mouse' option, a status line can
be dragged to resize windows.
Note: If you expect your status line to be in reverse video and it isn't,
check if the 'highlight' option contains "si". In version 3.0, this meant to
invert the status line. Now it should be "sr", reverse the status line, as
"si" now stands for italic! If italic is not available on your terminal, the
status line is inverted anyway; you will only see this problem on terminals
that have termcap codes for italics.
==============================================================================
3. Opening and closing a window *opening-window* *E36*
CTRL-W s *CTRL-W_s*
CTRL-W S *CTRL-W_S*
CTRL-W CTRL-S *CTRL-W_CTRL-S*
:[N]sp[lit] [++opt] [+cmd] *:sp* *:split*
Split current window in two. The result is two viewports on
the same file. Make new window N high (default is to use half
the height of the current window). Reduces the current window
height to create room (and others, if the 'equalalways' option
is set and 'eadirection' isn't "hor").
Note: CTRL-S does not work on all terminals and might block
further input, use CTRL-Q to get going again.
Also see |++opt| and |+cmd|.
CTRL-W CTRL-V *CTRL-W_CTRL-V*
CTRL-W v *CTRL-W_v*
:[N]vs[plit] [++opt] [+cmd] [file] *:vs* *:vsplit*
Like |:split|, but split vertically. If 'equalalways' is set
and 'eadirection' isn't "ver" the windows will be spread out
horizontally, unless a width was specified.
Note: In other places CTRL-Q does the same as CTRL-V, but here
it doesn't!
CTRL-W n *CTRL-W_n*
CTRL-W CTRL_N *CTRL-W_CTRL-N*
:[N]new [++opt] [+cmd] *:new*
Create a new window and start editing an empty file in it.
Make new window N high (default is to use half the existing
height). Reduces the current window height to create room (and
others, if the 'equalalways' option is set and 'eadirection'
isn't "hor").
Also see |++opt| and |+cmd|.
If 'fileformats' is not empty, the first format given will be
used for the new buffer. If 'fileformats' is empty, the
'fileformat' of the current buffer is used. This can be
overridden with the |++opt| argument.
Autocommands are executed in this order:
1. WinLeave for the current window
2. WinEnter for the new window
3. BufLeave for the current buffer
4. BufEnter for the new buffer
This behaves like a ":split" first, and then a ":e" command.
:[N]vne[w] [++opt] [+cmd] [file] *:vne* *:vnew*
Like |:new|, but split vertically. If 'equalalways' is set
and 'eadirection' isn't "ver" the windows will be spread out
horizontally, unless a width was specified.
:[N]new [++opt] [+cmd] {file}
:[N]sp[lit] [++opt] [+cmd] {file} *:split_f*
Create a new window and start editing file {file} in it.
If [+cmd] is given, execute the command when the file has been
loaded |+cmd|.
Also see |++opt|.
Make new window N high (default is to use half the existing
height). Reduces the current window height to create room
(and others, if the 'equalalways' option is set).
:[N]sv[iew] [++opt] [+cmd] {file} *:sv* *:sview* *splitview*
Same as ":split", but set 'readonly' option for this buffer.
:[N]sf[ind] [++opt] [+cmd] {file} *:sf* *:sfind* *splitfind*
Same as ":split", but search for {file} in 'path'. Doesn't
split if {file} is not found.
CTRL-W CTRL-^ *CTRL-W_CTRL-^* *CTRL-W_^*
CTRL-W ^ Does ":split #", split window in two and edit alternate file.
When a count is given, it becomes ":split #N", split window
and edit buffer N.
Note that the 'splitbelow' and 'splitright' options influence where a new
window will appear.
*:vert* *:vertical*
:vert[ical] {cmd}
Execute {cmd}. If it contains a command that splits a window,
it will be split vertically.
:lefta[bove] {cmd} *:lefta* *:leftabove*
:abo[veleft] {cmd} *:abo* *:aboveleft*
Execute {cmd}. If it contains a command that splits a window,
it will be opened left (vertical split) or above (horizontal
split) the current window. Overrules 'splitbelow' and
'splitright'.
:rightb[elow] {cmd} *:rightb* *:rightbelow*
:bel[owright] {cmd} *:bel* *:belowright*
Execute {cmd}. If it contains a command that splits a window,
it will be opened right (vertical split) or below (horizontal
split) the current window. Overrules 'splitbelow' and
'splitright'.
*:topleft* *E442*
:to[pleft] {cmd}
Execute {cmd}. If it contains a command that splits a window,
it will appear at the top and occupy the full width of the Vim
window. When the split is vertical the window appears at the
far left and occupies the full height of the Vim window.
*:botright*
:bo[tright] {cmd}
Execute {cmd}. If it contains a command that splits a window,
it will appear at the bottom and occupy the full width of the
Vim window. When the split is vertical the window appears at
the far right and occupies the full height of the Vim window.
These command modifiers can be combined to make a vertically split window
occupy the full height. Example: >
:vertical topleft edit tags
Opens a vertically split, full-height window on the "tags" file at the far
left of the Vim window.
Closing a window
----------------
CTRL-W q *CTRL-W_q*
CTRL-W CTRL-Q *CTRL-W_CTRL-Q*
:q[uit] Quit current window. When quitting the last window (not
counting a help window), exit Vim.
When 'hidden' is set, and there is only one window for the
current buffer, it becomes hidden.
When 'hidden' is not set, and there is only one window for the
current buffer, and the buffer was changed, the command fails.
(Note: CTRL-Q does not work on all terminals)
:q[uit]! Quit current window. If this was the last window for a buffer,
any changes to that buffer are lost. When quitting the last
window (not counting help windows), exit Vim. The contents of
the buffer are lost, even when 'hidden' is set.
CTRL-W c *CTRL-W_c* *:clo* *:close*
:clo[se][!] Close current window. When the 'hidden' option is set, or
when the buffer was changed and the [!] is used, the buffer
becomes hidden (unless there is another window editing it).
This command fails when: *E444*
- There is only one window on the screen.
- When 'hidden' is not set, [!] is not used, the buffer has
changes, and there is no other window on this buffer.
Changes to the buffer are not written and won't get lost, so
this is a "safe" command.
CTRL-W CTRL-C *CTRL-W_CTRL-C*
You might have expected that CTRL-W CTRL-C closes the current
window, but that does not work, because the CTRL-C cancels the
command.
*:hide*
:hid[e] Quit current window, unless it is the last window on the
screen. The buffer becomes hidden (unless there is another
window editing it or 'bufhidden' is "unload" or "delete").
The value of 'hidden' is irrelevant for this command.
Changes to the buffer are not written and won't get lost, so
this is a "safe" command.
:hid[e] {cmd} Execute {cmd} with 'hidden' is set. The previous value of
'hidden' is restored after {cmd} has been executed.
Example: >
:hide edit Makefile
< This will edit "Makefile", and hide the current buffer if it
has any changes.
CTRL-W o *CTRL-W_o* *E445*
CTRL-W CTRL-O *CTRL-W_CTRL-O* *:on* *:only*
:on[ly][!] Make the current window the only one on the screen. All other
windows are closed.
When the 'hidden' option is set, all buffers in closed windows
become hidden.
When 'hidden' is not set, and the 'autowrite' option is set,
modified buffers are written. Otherwise, windows that have
buffers that are modified are not removed, unless the [!] is
given, then they become hidden. But modified buffers are
never abandoned, so changes cannot get lost.
==============================================================================
4. Moving cursor to other windows *window-move-cursor*
CTRL-W <Down> *CTRL-W_<Down>*
CTRL-W CTRL-J *CTRL-W_CTRL-J* *CTRL-W_j*
CTRL-W j Move cursor to Nth window below current one. Uses the cursor
position to select between alternatives.
CTRL-W <Up> *CTRL-W_<Up>*
CTRL-W CTRL-K *CTRL-W_CTRL-K* *CTRL-W_k*
CTRL-W k Move cursor to Nth window above current one. Uses the cursor
position to select between alternatives.
CTRL-W <Left> *CTRL-W_<Left>*
CTRL-W CTRL-H *CTRL-W_CTRL-H*
CTRL-W <BS> *CTRL-W_<BS>* *CTRL-W_h*
CTRL-W h Move cursor to Nth window left of current one. Uses the
cursor position to select between alternatives.
CTRL-W <Right> *CTRL-W_<Right>*
CTRL-W CTRL-L *CTRL-W_CTRL-L* *CTRL-W_l*
CTRL-W l Move cursor to Nth window right of current one. Uses the
cursor position to select between alternatives.
CTRL-W w *CTRL-W_w* *CTRL-W_CTRL-W*
CTRL-W CTRL-W Without count: move cursor to window below/right of the
current one. If there is no window below or right, go to
top-left window.
With count: go to Nth window (windows are numbered from
top-left to bottom-right). To obtain the window number see
|bufwinnr()| and |winnr()|.
*CTRL-W_W*
CTRL-W W Without count: move cursor to window above/left of current
one. If there is no window above or left, go to bottom-right
window. With count: go to Nth window (windows are numbered
from top-left to bottom-right).
CTRL-W t *CTRL-W_t* *CTRL-W_CTRL-T*
CTRL-W CTRL-T Move cursor to top-left window.
CTRL-W b *CTRL-W_b* *CTRL-W_CTRL-B*
CTRL-W CTRL-B Move cursor to bottom-right window.
CTRL-W p *CTRL-W_p* *CTRL-W_CTRL-P*
CTRL-W CTRL-P Go to previous (last accessed) window.
*CTRL-W_P* *E441*
CTRL-W P Go to preview window. When there is no preview window this is
an error.
{not available when compiled without the |+quickfix| feature}
If Visual mode is active and the new window is not for the same buffer, the
Visual mode is ended. If the window is on the same buffer, the cursor
position is set to keep the same Visual area selected.
*:winc* *:wincmd*
These commands can also be executed with ":wincmd":
:[count]winc[md] {arg}
Like executing CTRL-W [count] {arg}. Example: >
:wincmd j
< Moves to the window below the current one.
This command is useful when a Normal mode cannot be used (for
the |CursorHold| autocommand event). Or when a Normal mode
command is inconvenient.
The count can also be a window number. Example: >
:exe nr . "wincmd w"
< This goes to window "nr".
==============================================================================
5. Moving windows around *window-moving*
CTRL-W r *CTRL-W_r* *CTRL-W_CTRL-R* *E443*
CTRL-W CTRL-R Rotate windows downwards/rightwards. The first window becomes
the second one, the second one becomes the third one, etc.
The last window becomes the first window. The cursor remains
in the same window.
This only works within the row or column of windows that the
current window is in.
*CTRL-W_R*
CTRL-W R Rotate windows upwards/leftwards. The second window becomes
the first one, the third one becomes the second one, etc. The
first window becomes the last window. The cursor remains in
the same window.
This only works within the row or column of windows that the
current window is in.
CTRL-W x *CTRL-W_x* *CTRL-W_CTRL-X*
CTRL-W CTRL-X Without count: Exchange current window with next one. If there
is no next window, exchange with previous window.
With count: Exchange current window with Nth window (first
window is 1). The cursor is put in the other window.
When vertical and horizontal window splits are mixed, the
exchange is only done in the row or column of windows that the
current window is in.
The following commands can be used to change the window layout. For example,
when there are two vertically split windows, CTRL-W K will change that in
horizontally split windows. CTRL-W H does it the other way around.
*CTRL-W_K*
CTRL-W K Move the current window to be at the very top, using the full
width of the screen. This works like closing the current
window and then creating another one with ":topleft split",
except that the current window contents is used for the new
window.
*CTRL-W_J*
CTRL-W J Move the current window to be at the very bottom, using the
full width of the screen. This works like closing the current
window and then creating another one with ":botright split",
except that the current window contents is used for the new
window.
*CTRL-W_H*
CTRL-W H Move the current window to be at the far left, using the
full height of the screen. This works like closing the
current window and then creating another one with
":vert topleft split", except that the current window contents
is used for the new window.
{not available when compiled without the +vertsplit feature}
*CTRL-W_L*
CTRL-W L Move the current window to be at the
|