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
|
*vim_win.txt* For Vim version 4.5. Last modification: 1996 Aug 6
Editing with multiple windows and 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.
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.
*hidden_buffer*
hidden: The buffer is not displayed. If there is a file for this buffer, it
has been read into the buffer. The buffer may have been modified.
*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.
In a table:
state displayed loaded ":buffers"
in window shows
active yes yes ' '
hidden no yes 'h'
inactive no no '-'
Starting Vim
------------
By default, Vim starts with one window, just like Vi.
The "-o" argument to Vim can be used to open a window for each file in the
argument list: "Vim -o file1 file2 file3" will open three windows.
"-oN", where N is a decimal number, opens N windows. If there are more
filenames than windows, only N windows are opened and some files do not get a
window. If there are more windows than filenames, the last few windows will
be editing empty buffers.
If there are many filenames, the windows will become very small. You might
want to set the 'winheight' option to create a workable situation.
Buf/Win Enter/Leave autocommands 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
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. 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.
Opening a new window
--------------------
CTRL-W s *CTRL-W_s*
CTRL-W S *CTRL-W_S*
CTRL-W CTRL-S *CTRL-W_CTRL-S*
:[N]sp[lit] *: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). (Note: CTRL-S does not work on all terminals).
CTRL-W n *CTRL-W_n*
CTRL-W CTRL_N *CTRL-W_CTRL-N*
:[N]new *: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).
:[N]new [+command] {file}
:[N]split [+command] {file} *:split_f*
Create a new window and start editing file {file} in it. If
[+command] is given, execute the command when the file has
been loaded. 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] [+command] {file} *:sv* *:sview*
Same as ":split", but set 'readonly' option for this buffer.
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.
Closing a window
----------------
CTRL-W q *CTRL-W_q*
CTRL-W CTRL-Q *CTRL-W_CTRL-Q*
:quit Quit current window, unless the buffer was changed and there
are no other windows for this buffer. When quitting the last
window (not counting help windows), exit Vim. (Note: CTRL-Q
does not work on all terminals)
:quit! 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.
CTRL-W CTRL-C *CTRL-W_CTRL-C*
CTRL-W c *CTRL-W_c* *:clo* *:close*
:clo[se] Quit current window, unless it is the last window on the
screen. The buffer becomes hidden (unless there is another
window editing it). (Note: CTRL-W CTRL-C does not work).
CTRL-W o *CTRL-W_o*
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. All buffers in the other windows become
hidden.
Moving the cursor to other windows
----------------------------------
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.
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.
CTRL-W w *CTRL-W_w* *CTRL-W_CTRL-W*
CTRL-W CTRL-W Without count: move cursor to window below current one. If
there is no window below, go to top window.
With count: go to Nth window.
*CTRL-W_W*
CTRL-W W Without count: move cursor to window above current one. If
there is no window above, go to bottom window.
With count: go to Nth window.
CTRL-W t *CTRL-W_t* *CTRL-W_CTRL-T*
CTRL-W CTRL-T move cursor to top window.
CTRL-W b *CTRL-W_b* *CTRL-W_CTRL-B*
CTRL-W CTRL-B move cursor to bottom window.
CTRL-W p *CTRL-W_p* *CTRL-W_CTRL-P*
CTRL-W CTRL-P go to previous (last accessed) window.
If Visual mode is active and the new window is not for the same buffer, the
Visual mode is ended.
Moving windows around
---------------------
CTRL-W r *CTRL-W_r* *CTRL-W_CTRL-R*
CTRL-W CTRL-R Rotate windows downwards. 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.
*CTRL-W_R*
CTRL-W R Rotate windows upwards. 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.
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.
Window resizing
---------------
*CTRL-W_=*
CTRL-W = make all windows (almost) equally high.
:res[ize] -N *:res* *:resize* *CTRL-W_-*
CTRL-W - decrease current window height by N
:resize +N *CTRL-W_+*
CTRL-W + increase current window height by N
:resize [N]
CTRL-W CTRL-_ *CTRL-W_CTRL-_* *CTRL-W__*
CTRL-W _ set current window height to N (default: highest possible)
z<nr><CR> set current window height to nr
You can also resize the window by dragging a status line up or down with the
mouse. This only works if the version of Vim that is being used supports the
mouse and the 'mouse' option has been set to enable it.
The option 'winheight' ('wh') is used to set the minimal window height of the
current window. This option is used each time another window becomes the
current window. If the option is '0', it is disabled. Set 'winheight' to a
very large value, e.g., '9999', to make the current window always fill all
available space. Set it to a reasonable value, e.g., '10', to make editing in
the current window comfortable.
When the option 'equalalways' ('ea') is set, all the windows are automatically
made the same size after splitting or closing a window. If you don't set this
option, splitting a window will reduce the size of the current window and
leave the other windows the same. When closing a window, the extra lines are
given to the window above it.
The option 'commandheight' ('ch') is used to set the height of the command
line. If you are annoyed by the "Hit RETURN to continue" questions for long
messages, set this option to 2 or 3.
If there is only one window, resizing that window will also change the command
line height. If there are several windows, resizing the current window will
also change the height of the window below it (and sometimes the window above
it).
Exiting Vim with multiple windows or buffers
--------------------------------------------
*:qa* *:qall*
:qa[ll] Exit Vim, unless there are some buffers which have been
changed. (Use ":bmod" to go to the next modified buffer).
:qall! Exit Vim. Any changes to buffers are lost.
:wqa[ll] *:wqa* *:wqall* *:xa* *:xall*
:xa[ll] Write all changed buffers and exit Vim. If there are buffers
without a file name, which are readonly or which cannot be
written for another reason, Vim is not quit.
:wqall!
:xall! Write all changed buffers, even the ones that are readonly,
and exit Vim. If there are buffers without a file name or
which cannot be written for another reason, Vim is not quit.
Writing with multiple buffers
-----------------------------
*:wa* *:wall*
:wa[ll] Write all changed buffers. Buffers without a file name or
which are readonly are not written.
:wa[ll]! Write all changed buffers, even the ones that are readonly.
Buffers without a file name are not written.
Overview of argument and buffer list commands
---------------------------------------------
args list buffer list meaning
1. :[N]argument [N] 11. :[N]buffer [N] to arg/buf N
2. :[N]next [file ..] 12. :[N]bnext [N] to Nth next arg/buf
3. :[N]Next [N] 13. :[N]bNext [N] to Nth previous arg/buf
4. :[N]previous [N] 14. :[N]bprevious [N] to Nth previous arg/buf
5. :rewind 15. :brewind to first arg/buf
6. :last 16. :blast to last arg/buf
7. :all 17. :ball edit all args/buffers
18. :unhide edit all loaded buffers
19. :[N]bmod [N] to Nth modified buf
split & args list split & buffer list meaning
21. :[N]sargument [N] 31. :[N]sbuffer [N] split + to arg/buf N
22. :[N]snext [file ..] 32. :[N]sbnext [N] split + to Nth next arg/buf
23. :[N]sNext [N] 33. :[N]sbNext [N] split + to Nth previous arg/buf
24. :[N]sprevious [N] 34. :[N]sbprevious [N] split + to Nth previous arg/buf
25. :srewind 35. :sbrewind split + to first arg/buf
26. :slast 36. :sblast split + to last arg/buf
27. :sall 37: :sball edit all args/buffers
38. :sunhide edit all loaded buffers
39. :[N]sbmod [N] split + to Nth modified buf
40. :args list of arguments
41. :buffers list of buffers
The meaning of [N] depends on the command:
[N] is number of buffers to go forward/backward on ?2, ?3, and ?4
[N] is an argument number, defaulting to current argument, for 1 and 21
[N] is a buffer number, defaulting to current buffer, for 11 and 31
[N] is a count for 19 and 39
Note: ":next" is an exception, because it must accept a list of file names
for compatibility with Vi.
The argument list and multiple windows
--------------------------------------
The current position in the argument list can be different for each window.
Remember that when doing ":e file", the position in the argument list stays
the same, but you are not editing the file at that position. To indicate
this, the file message (and the title, if you have one) shows
"(file (N) of M)", where "(N)" is the current position in the file list, and
"M" the number of files in the file list.
All the entries in the argument list are added to the buffer list. Thus, you
can also get to them with the buffer list commands, like ":bnext".
:[N]al[l] [N] *:al* *:all* *:sal* *:sall*
:[N]sal[l] [N] Rearrange the screen to open one window for each argument.
All other windows are closed (buffers become hidden). When a
count is given, this is the maximum number of windows to open.
Buf/Win Enter/Leave autocommands are not executed for the new
windows here, that's only done when they are really entered.
:[N]sa[rgument][!] [N] *:sa* *:sargument*
Short for ":split | argument [N]": split window and go to Nth
argument. But when there is no such argument, the window is
not split.
:[N]sn[ext][!] [file ..] *:sn* *:snext*
Short for ":split | [N]next": split window and go to Nth next
argument. But when there is no next file, the window is not
split.
:[N]spr[evious][!] [N] *:spr* *:sprevious*
:[N]sN[ext][!] [N] *:sN* *:sNext*
Short for ":split | [N]Next": split window and go to Nth
previous argument. But when there is no previous file, the
window is not split.
*:sr* *:srewind*
:sr[ewind][!] Short for ":split | rewind": split window and go to first
argument. But when there is no argument list, the window is
not split.
*:sla* *:slast*
:sla[st][!] Short for ":split | last": split window and go to last
argument. But when there is no argument list, the window is
not split.
Tag or file name under the cursor
---------------------------------
*:sta* *:stag*
:sta[g][!] [tagname]
Does ":tag[!] [tagname]" and splits the window for the found
tag. See also |:tag|.
CTRL-W ] *CTRL-W_]* *CTRL-W_CTRL-]*
CTRL-W CTRL-] split current window in two. Use identifier under cursor as a
tag and jump to it in the new upper window. Make new window N
high.
CTRL-W f *CTRL-W_f* *CTRL-W_CTRL-F*
CTRL-W CTRL-F split current window in two. Edit file name under cursor.
Like ":split ]f", but window isn't split if the file does not
exist. Uses the 'path' variable as a list of directory names
where to look for the file. Also the path for current file is
used to search for the file name. If the name is a hypertext
link that looks like "type://machine/path", only "/path" is
used.
Using hidden buffers
--------------------
A hidden buffer is not displayed in a window, but is still loaded into memory.
This makes it possible to jump from file to file, without the need to read or
write the file every time and having to keep the file in a window.
If the option 'hidden' ('hid') is set, abandoned buffers are kept for all
commands that start editing another file: ":edit", ":next", ":tag", etc. The
commands that move through the buffer list make the current buffer hidden
although the 'hidden' option is not set (see below).
You can make a hidden buffer not hidden by starting to edit it with any
command. Or by deleting it with the ":bdelete" command.
*hidden_quit*
When you try to quit Vim while there is a hidden, modified buffer, you will
get an error message and Vim will make that buffer the current buffer. You
can then decide to write this buffer (":wq") or quit without writing (":q!").
Be careful: there may be more hidden, modified buffers!
:files *:files*
:buffers *:buffers* *:ls*
:ls Show all buffers. Example:
1 #h "/test/text" line 1
2 - "asdf" line 0
3 % + "version.c" line 1
Each buffer has a unique number. That number will not change,
so you can always go to a specific buffer with ":buffer N" or
"N CTRL-^", where N is the buffer number.
'-' indicates a buffer that is not loaded. 'h' indicates a
hidden buffer: It is loaded, but currently not displayed in a
window. '%' indicates the buffer in the current window. '#'
indicates the alternate buffer for ":e #" or CTRL-^. '+'
indicates a modified buffer.
:[N]bd[elete] *:bd* *:bdelete*
:bd[elete] [N]
Unload buffer [N] (default: current buffer) and delete it from
the buffer list. If the buffer was changed, this fails. The
file remains unaffected. Any windows for this buffer are
closed. If buffer [N] is the current buffer, the next buffer
(displayed in a window) becomes the current buffer.
:[N]bdelete!
:bdelete! [N]
Unload buffer [N] (default: current buffer) and delete it from
the buffer list. If the buffer was changed the changes are
lost. The file remains unaffected. Any windows for this
buffer are closed. If buffer [N] is the current buffer, the
next buffer (displayed in a window) becomes the current
buffer.
:bdelete[!] {bufname}
Like ":bdelete[!] [N]", but buffer given by name. Note that a
buffer whose name is a number cannot be referenced by that
name; use the buffer number instead. Insert a backslash
before a space in a buffer name.
:N,Mbdelete[!] do ":bdelete[!]" for all buffers in the range N to M
(inclusive).
:bdelete[!] N1 N2 ...
do ":bdelete[!]" for buffer N1, N2, etc. The arguments can be
buffer numbers or buffer names (but not buffer names that are
a number). Insert a backslash before a space in a buffer
name.
:[N]bun[load] *:bun* *:bunload*
:bun[load] [N]
Unload buffer [N] (default: current buffer). The memory
allocated for this buffer will be freed. The buffer remains
in the buffer list. If the buffer was changed, this fails.
Any windows for this buffer are closed. If buffer [N] is the
current buffer, the next buffer (displayed in a window)
becomes the current buffer.
:[N]bunload!
:bunload! [N]
Unload buffer [N] (default: current buffer). The memory
allocated for this buffer will be freed. The buffer remains
in the buffer list. If the buffer was changed, the changes
are lost. Any windows for this buffer are closed. If buffer
[N] is the current buffer, the next buffer (displayed in a
window) becomes the current buffer.
:bunload[!] {bufname}
Like ":bunload[!] [N]", but buffer given by name. Note that a
buffer whose name is a number cannot be referenced by that
name; use the buffer number instead. Insert a backslash
before a space in a buffer name.
:N,Mbunload[!] do ":bunload[!]" for all buffers in the range N to M
(inclusive).
:bunload[!] N1 N2 ...
do ":bunload[!]" for buffer N1, N2, etc. The arguments can be
buffer numbers or buffer names (but not buffer names that are
a number). Insert a backslash before a space in a buffer
name.
:[N]b[uffer] [N] *:b* *:buffer*
Edit buffer [N] from the buffer list. If [N] is not given,
the current buffer remains being edited.
:[N]b[uffer] {filename}
Edit buffer for {filename} from the buffer list.
:[N]sb[uffer] [N] *:sb* *:sbuffer*
Split window and edit buffer [N] from the buffer list. If [N]
is not given, the current buffer is edited.
:[N]sb[uffer] {filename}
Split window and edit buffer for {filename} from the buffer
list.
*:bn* *:bnext*
:[N]bn[ext] [N]
Go to [N]th next buffer in buffer list. [N] defaults to one.
Wraps around the end of the buffer list.
*:sbn* *:sbnext*
:[N]sbn[ext] [N]
Split window and go to [N]th next buffer in buffer list.
Wraps around the end of the buffer list.
:[N]bN[ext] [N] *:bN* *:bNext* *:bp* *:bprevious*
:[N]bp[revious] [N]
Go to [N]th previous buffer in buffer list. [N] defaults to
one. Wraps around the start of the buffer list.
:[N]sbN[ext] [N] *:sbN* *:sbNext* *:sbp* *:sbprevious*
:[N]sbp[revious] [N]
Split window and go to [N]th previous buffer in buffer list.
Wraps around the start of the buffer list.
*:br* *:brewind*
:br[ewind] Go to first buffer in buffer list.
*:sbr* *:sbrewind*
:sbr[ewind] Split window and go to first buffer in buffer list
*:bl* *:blast*
:bl[ast] Go to last buffer in buffer list.
*:sbl* *:sblast*
:sbl[ast] Split window and go to last buffer in buffer list.
:[N]bm[odified] [N] *:bm* *:bmodified*
Go to [N]th next modified buffer in buffer list.
:[N]sbm[odified] [N] *:sbm* *:sbmodified*
Split window and go to [N]th next modified buffer in buffer
list.
:[N]unh[ide] [N] *:unh* *:unhide* *:sun* *:sunhide*
:[N]sun[hide] [N]
Rearrange the screen to open one window for each loaded buffer
in the buffer list. When a count is given, this is the
maximum number of windows to open.
:[N]ba[ll] [N] *:ba* *:ball* *:sba* *:sball*
:[N]sba[ll] [N] Rearrange the screen to open one window for each buffer in
the buffer list. When a count is given, this is the maximum
number of windows to open. Buf/Win Enter/Leave autocommands
are not executed for the new windows here, that's only done
when they are really entered.
Memory usage limits
-------------------
The option 'maxmem' ('mm') is used to set the maximum memory used for one
buffer (in kilobytes). 'maxmemtot' is used to set the maximum memory used for
all buffers (in kilobytes). The defaults depend on the system used. For the
Amiga and MS-DOS, 'maxmemtot' is set depending on the amount of memory
available. If you don't like Vim to swap to a file, set 'maxmem' and
'maxmemtot' to a very large value. The swapfile will then only be used for
recovery. If you don't want a swapfile at all, set 'updatecount' to 0, or
use the "-n" argument when starting Vim. Note that the 'maxmem' option is
only used when a buffer is created. Changing this option does not affect
buffers that have already been loaded. Thus you can set it to different
values for different files. 'maxmemtot' works always.
vim:ts=8:sw=8:js:tw=78:fo=tcq2:isk=!-~,^*,^\|,^\":
|