blob: 4ba6d4a268a2724292a441cf7b0bcbe375bee085 [file] [log] [blame]
Bram Moolenaar81695252004-12-29 20:58:21 +00001*windows.txt* For Vim version 7.0aa. Last change: 2004 Dec 29
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Editing with multiple windows and buffers. *windows* *buffers*
8
9The commands which have been added to use multiple windows and buffers are
10explained here. Additionally, there are explanations for commands that work
11differently when used in combination with more than one window.
12
13The basics are explained in chapter 7 and 8 of the user manual |usr_07.txt|
14|usr_08.txt|.
15
161. Introduction |windows-intro|
172. Starting Vim |windows-starting|
183. Opening and closing a window |opening-window|
194. Moving cursor to other windows |window-move-cursor|
205. Moving windows around |window-moving|
216. Window resizing |window-resize|
227. Argument and buffer list commands |buffer-list|
238. Do a command in all buffers or windows |list-repeat|
249. Tag or file name under the cursor |window-tag|
2510. The preview window |preview-window|
2611. Using hidden buffers |buffer-hidden|
2712. Special kinds of buffers |special-buffers|
28
29{Vi does not have any of these commands}
30{not able to use multiple windows when the |+windows| feature was disabled at
31compile time}
32{not able to use vertically split windows when the |+vertsplit| feature was
33disabled at compile time}
34
35==============================================================================
361. Introduction *windows-intro*
37
38A window is a viewport onto a buffer. You can use multiple windows on one
39buffer, or several windows on different buffers.
40
41A buffer is a file loaded into memory for editing. The original file remains
42unchanged until you write the buffer to the file.
43
44A buffer can be in one of three states:
45
46 *active-buffer*
47active: The buffer is displayed in a window. If there is a file for this
48 buffer, it has been read into the buffer. The buffer may have been
49 modified since then and thus be different from the file.
50 *hidden-buffer*
51hidden: The buffer is not displayed. If there is a file for this buffer, it
52 has been read into the buffer. Otherwise it's the same as an active
53 buffer, you just can't see it.
54 *inactive-buffer*
55inactive: The buffer is not displayed and does not contain anything. Options
56 for the buffer are remembered if the file was once loaded. It can
57 contain marks from the |viminfo| file. But the buffer doesn't
58 contain text.
59
60In a table:
61
62state displayed loaded ":buffers" ~
63 in window shows ~
64active yes yes 'a'
65hidden no yes 'h'
66inactive no no ' '
67
68Note: All CTRL-W commands can also be executed with |:wincmd|, for those
69places where a Normal mode command can't be used or is inconvenient.
70
71==============================================================================
722. Starting Vim *windows-starting*
73
74By default, Vim starts with one window, just like Vi.
75
76The "-o" and "-O" arguments to Vim can be used to open a window for each file
77in the argument list. The "-o" argument will split the windows horizontally;
78the "-O" argument will split the windows vertically. If both "-o" and "-O"
79are given, the last one encountered will be used to determine the split
80orientation. For example, this will open three windows, split horizontally: >
81 vim -o file1 file2 file3
82
83"-oN", where N is a decimal number, opens N windows split horizontally. If
84there are more file names than windows, only N windows are opened and some
85files do not get a window. If there are more windows than file names, the
86last few windows will be editing empty buffers. Similarly, "-ON" opens N
87windows split vertically, with the same restrictions.
88
89If there are many file names, the windows will become very small. You might
90want to set the 'winheight' and/or 'winwidth' options to create a workable
91situation.
92
93Buf/Win Enter/Leave |autocommand|s are not executed when opening the new
94windows and reading the files, that's only done when they are really entered.
95
96 *status-line*
97A status line will be used to separate windows. The 'laststatus' option tells
98when the last window also has a status line:
99 'laststatus' = 0 never a status line
100 'laststatus' = 1 status line if there is more than one window
101 'laststatus' = 2 always a status line
102
103You can change the contents of the status line with the 'statusline' option.
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +0000104This option can be local to the window, so that you can have a different
105status line in each window.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106
107Normally, inversion is used to display the status line. This can be changed
108with the 's' character in the 'highlight' option. For example, "sb" sets it to
109bold characters. If no highlighting is used for the status line ("sn"), the
110'^' character is used for the current window, and '=' for other windows. If
111the mouse is supported and enabled with the 'mouse' option, a status line can
112be dragged to resize windows.
113
114Note: If you expect your status line to be in reverse video and it isn't,
115check if the 'highlight' option contains "si". In version 3.0, this meant to
116invert the status line. Now it should be "sr", reverse the status line, as
117"si" now stands for italic! If italic is not available on your terminal, the
118status line is inverted anyway; you will only see this problem on terminals
119that have termcap codes for italics.
120
121==============================================================================
1223. Opening and closing a window *opening-window* *E36*
123
124CTRL-W s *CTRL-W_s*
125CTRL-W S *CTRL-W_S*
126CTRL-W CTRL-S *CTRL-W_CTRL-S*
127:[N]sp[lit] [++opt] [+cmd] *:sp* *:split*
128 Split current window in two. The result is two viewports on
129 the same file. Make new window N high (default is to use half
130 the height of the current window). Reduces the current window
131 height to create room (and others, if the 'equalalways' option
132 is set and 'eadirection' isn't "hor").
133 Note: CTRL-S does not work on all terminals and might block
134 further input, use CTRL-Q to get going again.
135 Also see |++opt| and |+cmd|.
136
137CTRL-W CTRL-V *CTRL-W_CTRL-V*
138CTRL-W v *CTRL-W_v*
139:[N]vs[plit] [++opt] [+cmd] [file] *:vs* *:vsplit*
140 Like |:split|, but split vertically. If 'equalalways' is set
141 and 'eadirection' isn't "ver" the windows will be spread out
142 horizontally, unless a width was specified.
143 Note: In other places CTRL-Q does the same as CTRL-V, but here
144 it doesn't!
145
146CTRL-W n *CTRL-W_n*
147CTRL-W CTRL_N *CTRL-W_CTRL-N*
148:[N]new [++opt] [+cmd] *:new*
149 Create a new window and start editing an empty file in it.
150 Make new window N high (default is to use half the existing
151 height). Reduces the current window height to create room (and
152 others, if the 'equalalways' option is set and 'eadirection'
153 isn't "hor").
154 Also see |++opt| and |+cmd|.
155 If 'fileformats' is not empty, the first format given will be
156 used for the new buffer. If 'fileformats' is empty, the
157 'fileformat' of the current buffer is used. This can be
158 overridden with the |++opt| argument.
159 Autocommands are executed in this order:
160 1. WinLeave for the current window
161 2. WinEnter for the new window
162 3. BufLeave for the current buffer
163 4. BufEnter for the new buffer
164 This behaves like a ":split" first, and then a ":e" command.
165
166:[N]vne[w] [++opt] [+cmd] [file] *:vne* *:vnew*
167 Like |:new|, but split vertically. If 'equalalways' is set
168 and 'eadirection' isn't "ver" the windows will be spread out
169 horizontally, unless a width was specified.
170
171:[N]new [++opt] [+cmd] {file}
172:[N]sp[lit] [++opt] [+cmd] {file} *:split_f*
173 Create a new window and start editing file {file} in it.
174 If [+cmd] is given, execute the command when the file has been
175 loaded |+cmd|.
176 Also see |++opt|.
177 Make new window N high (default is to use half the existing
178 height). Reduces the current window height to create room
179 (and others, if the 'equalalways' option is set).
180
181:[N]sv[iew] [++opt] [+cmd] {file} *:sv* *:sview* *splitview*
182 Same as ":split", but set 'readonly' option for this buffer.
183
184:[N]sf[ind] [++opt] [+cmd] {file} *:sf* *:sfind* *splitfind*
185 Same as ":split", but search for {file} in 'path'. Doesn't
186 split if {file} is not found.
187
188CTRL-W CTRL-^ *CTRL-W_CTRL-^* *CTRL-W_^*
189CTRL-W ^ Does ":split #", split window in two and edit alternate file.
190 When a count is given, it becomes ":split #N", split window
191 and edit buffer N.
192
193Note that the 'splitbelow' and 'splitright' options influence where a new
194window will appear.
195
196 *:vert* *:vertical*
197:vert[ical] {cmd}
198 Execute {cmd}. If it contains a command that splits a window,
199 it will be split vertically.
200
201:lefta[bove] {cmd} *:lefta* *:leftabove*
202:abo[veleft] {cmd} *:abo* *:aboveleft*
203 Execute {cmd}. If it contains a command that splits a window,
204 it will be opened left (vertical split) or above (horizontal
205 split) the current window. Overrules 'splitbelow' and
206 'splitright'.
207
208:rightb[elow] {cmd} *:rightb* *:rightbelow*
209:bel[owright] {cmd} *:bel* *:belowright*
210 Execute {cmd}. If it contains a command that splits a window,
211 it will be opened right (vertical split) or below (horizontal
212 split) the current window. Overrules 'splitbelow' and
213 'splitright'.
214
215 *:topleft* *E442*
216:to[pleft] {cmd}
217 Execute {cmd}. If it contains a command that splits a window,
218 it will appear at the top and occupy the full width of the Vim
219 window. When the split is vertical the window appears at the
220 far left and occupies the full height of the Vim window.
221
222 *:botright*
223:bo[tright] {cmd}
224 Execute {cmd}. If it contains a command that splits a window,
225 it will appear at the bottom and occupy the full width of the
226 Vim window. When the split is vertical the window appears at
227 the far right and occupies the full height of the Vim window.
228
229These command modifiers can be combined to make a vertically split window
230occupy the full height. Example: >
231 :vertical topleft edit tags
232Opens a vertically split, full-height window on the "tags" file at the far
233left of the Vim window.
234
235
236Closing a window
237----------------
238
239CTRL-W q *CTRL-W_q*
240CTRL-W CTRL-Q *CTRL-W_CTRL-Q*
241:q[uit] Quit current window. When quitting the last window (not
242 counting a help window), exit Vim.
243 When 'hidden' is set, and there is only one window for the
244 current buffer, it becomes hidden.
245 When 'hidden' is not set, and there is only one window for the
246 current buffer, and the buffer was changed, the command fails.
247 (Note: CTRL-Q does not work on all terminals)
248
249:q[uit]! Quit current window. If this was the last window for a buffer,
250 any changes to that buffer are lost. When quitting the last
251 window (not counting help windows), exit Vim. The contents of
252 the buffer are lost, even when 'hidden' is set.
253
254CTRL-W c *CTRL-W_c* *:clo* *:close*
255:clo[se][!] Close current window. When the 'hidden' option is set, or
256 when the buffer was changed and the [!] is used, the buffer
257 becomes hidden (unless there is another window editing it).
258 This command fails when: *E444*
259 - There is only one window on the screen.
260 - When 'hidden' is not set, [!] is not used, the buffer has
261 changes, and there is no other window on this buffer.
262 Changes to the buffer are not written and won't get lost, so
263 this is a "safe" command.
264
265CTRL-W CTRL-C *CTRL-W_CTRL-C*
266 You might have expected that CTRL-W CTRL-C closes the current
267 window, but that does not work, because the CTRL-C cancels the
268 command.
269
270 *:hide*
271:hid[e] Quit current window, unless it is the last window on the
272 screen. The buffer becomes hidden (unless there is another
273 window editing it or 'bufhidden' is "unload" or "delete").
274 The value of 'hidden' is irrelevant for this command.
275 Changes to the buffer are not written and won't get lost, so
276 this is a "safe" command.
277
278:hid[e] {cmd} Execute {cmd} with 'hidden' is set. The previous value of
279 'hidden' is restored after {cmd} has been executed.
280 Example: >
281 :hide edit Makefile
282< This will edit "Makefile", and hide the current buffer if it
283 has any changes.
284
285CTRL-W o *CTRL-W_o* *E445*
286CTRL-W CTRL-O *CTRL-W_CTRL-O* *:on* *:only*
287:on[ly][!] Make the current window the only one on the screen. All other
288 windows are closed.
289 When the 'hidden' option is set, all buffers in closed windows
290 become hidden.
291 When 'hidden' is not set, and the 'autowrite' option is set,
292 modified buffers are written. Otherwise, windows that have
293 buffers that are modified are not removed, unless the [!] is
294 given, then they become hidden. But modified buffers are
295 never abandoned, so changes cannot get lost.
296
297==============================================================================
2984. Moving cursor to other windows *window-move-cursor*
299
300CTRL-W <Down> *CTRL-W_<Down>*
301CTRL-W CTRL-J *CTRL-W_CTRL-J* *CTRL-W_j*
302CTRL-W j Move cursor to Nth window below current one. Uses the cursor
303 position to select between alternatives.
304
305CTRL-W <Up> *CTRL-W_<Up>*
306CTRL-W CTRL-K *CTRL-W_CTRL-K* *CTRL-W_k*
307CTRL-W k Move cursor to Nth window above current one. Uses the cursor
308 position to select between alternatives.
309
310CTRL-W <Left> *CTRL-W_<Left>*
311CTRL-W CTRL-H *CTRL-W_CTRL-H*
312CTRL-W <BS> *CTRL-W_<BS>* *CTRL-W_h*
313CTRL-W h Move cursor to Nth window left of current one. Uses the
314 cursor position to select between alternatives.
315
316CTRL-W <Right> *CTRL-W_<Right>*
317CTRL-W CTRL-L *CTRL-W_CTRL-L* *CTRL-W_l*
318CTRL-W l Move cursor to Nth window right of current one. Uses the
319 cursor position to select between alternatives.
320
321CTRL-W w *CTRL-W_w* *CTRL-W_CTRL-W*
322CTRL-W CTRL-W Without count: move cursor to window below/right of the
323 current one. If there is no window below or right, go to
324 top-left window.
325 With count: go to Nth window (windows are numbered from
326 top-left to bottom-right). To obtain the window number see
327 |bufwinnr()| and |winnr()|.
328
329 *CTRL-W_W*
330CTRL-W W Without count: move cursor to window above/left of current
331 one. If there is no window above or left, go to bottom-right
332 window. With count: go to Nth window (windows are numbered
333 from top-left to bottom-right).
334
335CTRL-W t *CTRL-W_t* *CTRL-W_CTRL-T*
336CTRL-W CTRL-T Move cursor to top-left window.
337
338CTRL-W b *CTRL-W_b* *CTRL-W_CTRL-B*
339CTRL-W CTRL-B Move cursor to bottom-right window.
340
341CTRL-W p *CTRL-W_p* *CTRL-W_CTRL-P*
342CTRL-W CTRL-P Go to previous (last accessed) window.
343
344 *CTRL-W_P* *E441*
345CTRL-W P Go to preview window. When there is no preview window this is
346 an error.
347 {not available when compiled without the |+quickfix| feature}
348
349If Visual mode is active and the new window is not for the same buffer, the
350Visual mode is ended. If the window is on the same buffer, the cursor
351position is set to keep the same Visual area selected.
352
353 *:winc* *:wincmd*
354These commands can also be executed with ":wincmd":
355
356:[count]winc[md] {arg}
357 Like executing CTRL-W [count] {arg}. Example: >
358 :wincmd j
359< Moves to the window below the current one.
360 This command is useful when a Normal mode cannot be used (for
361 the |CursorHold| autocommand event). Or when a Normal mode
362 command is inconvenient.
363 The count can also be a window number. Example: >
364 :exe nr . "wincmd w"
365< This goes to window "nr".
366
367==============================================================================
3685. Moving windows around *window-moving*
369
370CTRL-W r *CTRL-W_r* *CTRL-W_CTRL-R* *E443*
371CTRL-W CTRL-R Rotate windows downwards/rightwards. The first window becomes
372 the second one, the second one becomes the third one, etc.
373 The last window becomes the first window. The cursor remains
374 in the same window.
375 This only works within the row or column of windows that the
376 current window is in.
377
378 *CTRL-W_R*
379CTRL-W R Rotate windows upwards/leftwards. The second window becomes
380 the first one, the third one becomes the second one, etc. The
381 first window becomes the last window. The cursor remains in
382 the same window.
383 This only works within the row or column of windows that the
384 current window is in.
385
386CTRL-W x *CTRL-W_x* *CTRL-W_CTRL-X*
387CTRL-W CTRL-X Without count: Exchange current window with next one. If there
388 is no next window, exchange with previous window.
389 With count: Exchange current window with Nth window (first
390 window is 1). The cursor is put in the other window.
391 When vertical and horizontal window splits are mixed, the
392 exchange is only done in the row or column of windows that the
393 current window is in.
394
395The following commands can be used to change the window layout. For example,
396when there are two vertically split windows, CTRL-W K will change that in
397horizontally split windows. CTRL-W H does it the other way around.
398
399 *CTRL-W_K*
400CTRL-W K Move the current window to be at the very top, using the full
401 width of the screen. This works like closing the current
402 window and then creating another one with ":topleft split",
403 except that the current window contents is used for the new
404 window.
405
406 *CTRL-W_J*
407CTRL-W J Move the current window to be at the very bottom, using the
408 full width of the screen. This works like closing the current
409 window and then creating another one with ":botright split",
410 except that the current window contents is used for the new
411 window.
412
413 *CTRL-W_H*
414CTRL-W H Move the current window to be at the far left, using the
415 full height of the screen. This works like closing the
416 current window and then creating another one with
417 ":vert topleft split", except that the current window contents
418 is used for the new window.
419 {not available when compiled without the +vertsplit feature}
420
421 *CTRL-W_L*
422CTRL-W L Move the current window to be at the far right, using the full
423 height of the screen. This works like closing the
424 current window and then creating another one with
425 ":vert botright split", except that the current window
426 contents is used for the new window.
427 {not available when compiled without the +vertsplit feature}
428
429==============================================================================
4306. Window resizing *window-resize*
431
432 *CTRL-W_=*
433CTRL-W = Make all windows (almost) equally high and wide, but use
434 'winheight' and 'winwidth' for the current window.
435
436:res[ize] -N *:res* *:resize* *CTRL-W_-*
437CTRL-W - Decrease current window height by N (default 1).
438 If used after 'vertical': decrease width by N.
439
440:res[ize] +N *CTRL-W_+*
441CTRL-W + Increase current window height by N (default 1).
442 If used after 'vertical': increase width by N.
443
444:res[ize] [N]
445CTRL-W CTRL-_ *CTRL-W_CTRL-_* *CTRL-W__*
446CTRL-W _ Set current window height to N (default: highest possible).
447
448z{nr}<CR> Set current window height to {nr}.
449
450 *CTRL-W_<*
451CTRL-W < Decrease current window width by N (default 1).
452
453 *CTRL-W_>*
454CTRL-W > Increase current window width by N (default 1).
455
456:vertical res[ize] [N] *:vertical-resize* *CTRL-W_bar*
457CTRL-W | Set current window width to N (default: widest possible).
458
459You can also resize a window by dragging a status line up or down with the
460mouse. Or by dragging a vertical separator line left or right. This only
461works if the version of Vim that is being used supports the mouse and the
462'mouse' option has been set to enable it.
463
464The option 'winheight' ('wh') is used to set the minimal window height of the
465current window. This option is used each time another window becomes the
466current window. If the option is '0', it is disabled. Set 'winheight' to a
467very large value, e.g., '9999', to make the current window always fill all
468available space. Set it to a reasonable value, e.g., '10', to make editing in
469the current window comfortable.
470
471The equivalent 'winwidth' ('wiw') option is used to set the minimal width of
472the current window.
473
474When the option 'equalalways' ('ea') is set, all the windows are automatically
475made the same size after splitting or closing a window. If you don't set this
476option, splitting a window will reduce the size of the current window and
477leave the other windows the same. When closing a window, the extra lines are
478given to the window above it.
479
480The 'eadirection' option limits the direction in which the 'equalalways'
481option is applied. The default "both" resizes in both directions. When the
482value is "ver" only the heights of windows are equalized. Use this when you
483have manually resized a vertically split window and want to keep this width.
484Likewise, "hor" causes only the widths of windows to be equalized.
485
486The option 'cmdheight' ('ch') is used to set the height of the command-line.
487If you are annoyed by the |hit-enter| prompt for long messages, set this
488option to 2 or 3.
489
490If there is only one window, resizing that window will also change the command
491line height. If there are several windows, resizing the current window will
492also change the height of the window below it (and sometimes the window above
493it).
494
495The minimal height and width of a window is set with 'winminheight' and
496'winminwidth'. These are hard values, a window will never become smaller.
497
498==============================================================================
4997. Argument and buffer list commands *buffer-list*
500
501 args list buffer list meaning ~
5021. :[N]argument [N] 11. :[N]buffer [N] to arg/buf N
5032. :[N]next [file ..] 12. :[N]bnext [N] to Nth next arg/buf
5043. :[N]Next [N] 13. :[N]bNext [N] to Nth previous arg/buf
5054. :[N]previous [N] 14. :[N]bprevious [N] to Nth previous arg/buf
5065. :rewind / :first 15. :brewind / :bfirst to first arg/buf
5076. :last 16. :blast to last arg/buf
5087. :all 17. :ball edit all args/buffers
509 18. :unhide edit all loaded buffers
510 19. :[N]bmod [N] to Nth modified buf
511
512 split & args list split & buffer list meaning ~
51321. :[N]sargument [N] 31. :[N]sbuffer [N] split + to arg/buf N
51422. :[N]snext [file ..] 32. :[N]sbnext [N] split + to Nth next arg/buf
51523. :[N]sNext [N] 33. :[N]sbNext [N] split + to Nth previous arg/buf
51624. :[N]sprevious [N] 34. :[N]sbprevious [N] split + to Nth previous arg/buf
51725. :srewind / :sfirst 35. :sbrewind / :sbfirst split + to first arg/buf
51826. :slast 36. :sblast split + to last arg/buf
51927. :sall 37: :sball edit all args/buffers
520 38. :sunhide edit all loaded buffers
521 39. :[N]sbmod [N] split + to Nth modified buf
522
52340. :args list of arguments
52441. :buffers list of buffers
525
526The meaning of [N] depends on the command:
527 [N] is number of buffers to go forward/backward on ?2, ?3, and ?4
528 [N] is an argument number, defaulting to current argument, for 1 and 21
529 [N] is a buffer number, defaulting to current buffer, for 11 and 31
530 [N] is a count for 19 and 39
531
532Note: ":next" is an exception, because it must accept a list of file names
533for compatibility with Vi.
534
535
536The argument list and multiple windows
537--------------------------------------
538
539The current position in the argument list can be different for each window.
540Remember that when doing ":e file", the position in the argument list stays
541the same, but you are not editing the file at that position. To indicate
542this, the file message (and the title, if you have one) shows
543"(file (N) of M)", where "(N)" is the current position in the file list, and
544"M" the number of files in the file list.
545
546All the entries in the argument list are added to the buffer list. Thus, you
547can also get to them with the buffer list commands, like ":bnext".
548
549:[N]al[l][!] [N] *:al* *:all* *:sal* *:sall*
550:[N]sal[l][!] [N]
551 Rearrange the screen to open one window for each argument.
552 All other windows are closed. When a count is given, this is
553 the maximum number of windows to open.
554 When the 'hidden' option is set, all buffers in closed windows
555 become hidden.
556 When 'hidden' is not set, and the 'autowrite' option is set,
557 modified buffers are written. Otherwise, windows that have
558 buffers that are modified are not removed, unless the [!] is
559 given, then they become hidden. But modified buffers are
560 never abandoned, so changes cannot get lost.
561 [N] is the maximum number of windows to open. 'winheight'
562 also limits the number of windows opened ('winwidth' if
563 |:vertical| was prepended).
564 Buf/Win Enter/Leave autocommands are not executed for the new
565 windows here, that's only done when they are really entered.
566
567:[N]sa[rgument][!] [++opt] [+cmd] [N] *:sa* *:sargument*
568 Short for ":split | argument [N]": split window and go to Nth
569 argument. But when there is no such argument, the window is
570 not split. Also see |++opt| and |+cmd|.
571
572:[N]sn[ext][!] [++opt] [+cmd] [file ..] *:sn* *:snext*
573 Short for ":split | [N]next": split window and go to Nth next
574 argument. But when there is no next file, the window is not
575 split. Also see |++opt| and |+cmd|.
576
577:[N]spr[evious][!] [++opt] [+cmd] [N] *:spr* *:sprevious*
578:[N]sN[ext][!] [++opt] [+cmd] [N] *:sN* *:sNext*
579 Short for ":split | [N]Next": split window and go to Nth
580 previous argument. But when there is no previous file, the
581 window is not split. Also see |++opt| and |+cmd|.
582
583 *:sre* *:srewind*
584:sre[wind][!] [++opt] [+cmd]
585 Short for ":split | rewind": split window and go to first
586 argument. But when there is no argument list, the window is
587 not split. Also see |++opt| and |+cmd|.
588
589 *:sfir* *:sfirst*
590:sfir[st [++opt] [+cmd]
591 Same as ":srewind".
592
593 *:sla* *:slast*
594:sla[st][!] [++opt] [+cmd]
595 Short for ":split | last": split window and go to last
596 argument. But when there is no argument list, the window is
597 not split. Also see |++opt| and |+cmd|.
598
599 *:dr* *:drop*
600:dr[op] {file} ..
601 Edit the first {file} in a window.
602 - If the file is already open in a window change to that
603 window.
604 - If the file is not open in a window edit the file in the
605 current window. If the current buffer can't be |abandon|ed,
606 the window is split first.
607 The |argument-list| is set, like with the |:next| command.
608 The purpose of this command is that it can be used from a
609 program that wants Vim to edit another file, e.g., a debugger.
610 {only available when compiled with the +gui feature}
611
612==============================================================================
6138. Do a command in all buffers or windows *list-repeat*
614
615 *:windo*
616:windo[!] {cmd} Execute {cmd} in each window.
617 It works like doing this: >
618 CTRL-W t
619 :{cmd}
620 CTRL-W w
621 :{cmd}
622 etc.
623< When an error is detected on one window, further
624 windows will not be visited.
625 The last window (or where an error occurred) becomes
626 the current window.
627 {cmd} can contain '|' to concatenate several commands.
628 {cmd} must not open or close windows or reorder them.
629 {not in Vi} {not available when compiled without the
630 |+listcmds| feature}
631 Also see |:argdo| and |:bufdo|.
632
633 *:bufdo*
634:bufdo[!] {cmd} Execute {cmd} in each buffer in the buffer list.
635 It works like doing this: >
636 :bfirst
637 :{cmd}
638 :bnext
639 :{cmd}
640 etc.
641< When the current file can't be |abandon|ed and the [!]
642 is not present, the command fails.
643 When an error is detected on one buffer, further
644 buffers will not be visited.
645 Unlisted buffers are skipped.
646 The last buffer (or where an error occurred) becomes
647 the current buffer.
648 {cmd} can contain '|' to concatenate several commands.
649 {cmd} must not delete buffers or add buffers to the
650 buffer list.
651 Note: While this command is executing, the Syntax
652 autocommand event is disabled by adding it to
653 'eventignore'. This considerably speeds up editing
654 each buffer.
655 {not in Vi} {not available when compiled without the
656 |+listcmds| feature}
657 Also see |:argdo| and |:windo|.
658
659Examples: >
660
661 :windo set nolist nofoldcolumn | normal zn
662
663This resets the 'list' option and disables folding in all windows. >
664
665 :bufdo set fileencoding= | update
666
667This resets the 'fileencoding' in each buffer and writes it if this changed
668the buffer. The result is that all buffers will use the 'encoding' encoding
669(if conversion works properly).
670
671==============================================================================
6729. Tag or file name under the cursor *window-tag*
673
674 *:sta* *:stag*
675:sta[g][!] [tagname]
676 Does ":tag[!] [tagname]" and splits the window for the found
677 tag. See also |:tag|.
678
679CTRL-W ] *CTRL-W_]* *CTRL-W_CTRL-]*
680CTRL-W CTRL-] Split current window in two. Use identifier under cursor as a
681 tag and jump to it in the new upper window. Make new window N
682 high.
683
684 *CTRL-W_g]*
685CTRL-W g ] Split current window in two. Use identifier under cursor as a
686 tag and perform ":tselect" on it in the new upper window.
687 Make new window N high.
688
689 *CTRL-W_g_CTRL-]*
690CTRL-W g CTRL-] Split current window in two. Use identifier under cursor as a
691 tag and perform ":tjump" on it in the new upper window. Make
692 new window N high.
693
694CTRL-W f *CTRL-W_f* *CTRL-W_CTRL-F*
695CTRL-W CTRL-F Split current window in two. Edit file name under cursor.
696 Like ":split ]f", but window isn't split if the file does not
697 exist.
698 Uses the 'path' variable as a list of directory names where to
699 look for the file. Also the path for current file is
700 used to search for the file name.
701 If the name is a hypertext link that looks like
702 "type://machine/path", only "/path" is used.
703 If a count is given, the count'th matching file is edited.
704 {not available when the |+file_in_path| feature was disabled
705 at compile time}
706
707Also see |CTRL-W_CTRL-I|: open window for an included file that includes
708the keyword under the cursor.
709
710==============================================================================
71110. The preview window *preview-window*
712
713The preview window is a special window to show (preview) another file. It is
714normally a small window used to show an include file or definition of a
715function.
716{not available when compiled without the |+quickfix| feature}
717
718There can be only one preview window. It is created with one of the commands
719below. The 'previewheight' option can be set to specify the height of the
720preview window when it's opened. The 'previewwindow' option is set in the
721preview window to be able to recognize it. The 'winfixheight' option is set
722to have it keep the same height when opening/closing other windows.
723
724 *:pta* *:ptag*
725:pta[g][!] [tagname]
726 Does ":tag[!] [tagname]" and shows the found tag in a
727 "Preview" window without changing the current buffer or cursor
728 position. If a "Preview" window already exists, it is re-used
729 (like a help window is). If a new one is opened,
730 'previewheight' is used for the height of the window. See
731 also |:tag|.
732 See below for an example. |CursorHold-example|
733 Small difference from |:tag|: When [tagname] is equal to the
734 already displayed tag, the position in the matching tag list
735 is not reset. This makes the CursorHold example work after a
736 |:ptnext|.
737
738CTRL-W z *CTRL-W_z*
739CTRL-W CTRL-Z *CTRL-W_CTRL-Z* *:pc* *:pclose*
740:pc[lose][!] Close any "Preview" window currently open. When the 'hidden'
741 option is set, or when the buffer was changed and the [!] is
742 used, the buffer becomes hidden (unless there is another
743 window editing it). The command fails if any "Preview" buffer
744 cannot be closed. See also |:close|.
745
746 *:pp* *:ppop*
747:[count]pp[op][!]
748 Does ":[count]pop[!]" in the preview window. See |:pop| and
749 |:ptag|. {not in Vi}
750
751CTRL-W } *CTRL-W_}*
752 Use identifier under cursor as a tag and perform a :ptag on
753 it. Make the new Preview window (if required) N high. If N is
754 not given, 'previewheight' is used.
755
756CTRL-W g } *CTRL-W_g}*
757 Use identifier under cursor as a tag and perform a :ptjump on
758 it. Make the new Preview window (if required) N high. If N is
759 not given, 'previewheight' is used.
760
761 *:ped* *:pedit*
762:ped[it][!] [++opt] [+cmd] {file}
763 Edit {file} in the preview window. The preview window is
764 opened like with |:ptag|. The current window and cursor
765 position isn't changed. Useful example: >
766 :pedit +/fputc /usr/include/stdio.h
767<
768 *:ps* *:psearch*
769:[range]ps[earch][!] [count] [/]pattern[/]
770 Works like |:ijump| but shows the found match in the preview
771 window. The preview window is opened like with |:ptag|. The
772 current window and cursor position isn't changed. Useful
773 example: >
774 :psearch popen
775< Like with the |:ptag| command, you can use this to
776 automatically show information about the word under the
777 cursor. This is less clever than using |:ptag|, but you don't
778 need a tags file and it will also find matches in system
779 include files. Example: >
780 :au! CursorHold *.[ch] nested exe "silent! psearch " . expand("<cword>")
781< Warning: This can be slow.
782
783Example *CursorHold-example* >
784
785 :au! CursorHold *.[ch] nested exe "silent! ptag " . expand("<cword>")
786
787This will cause a ":ptag" to be executed for the keyword under the cursor,
788when the cursor hasn't moved for the time set with 'updatetime'. The "nested"
789makes other autocommands be executed, so that syntax highlighting works in the
790preview window. The "silent!" avoids an error message when the tag could not
791be found. Also see |CursorHold|. To disable this again: >
792
793 :au! CursorHold
794
795A nice addition is to highlight the found tag, avoid the ":ptag" when there
796is no word under the cursor, and a few other things: >
797
798 :au! CursorHold *.[ch] nested call PreviewWord()
799 :func PreviewWord()
800 : if &previewwindow " don't do this in the preview window
801 : return
802 : endif
803 : let w = expand("<cword>") " get the word under cursor
804 : if w =~ '\a' " if the word contains a letter
805 :
806 : " Delete any existing highlight before showing another tag
807 : silent! wincmd P " jump to preview window
808 : if &previewwindow " if we really get there...
809 : match none " delete existing highlight
810 : wincmd p " back to old window
811 : endif
812 :
813 : " Try displaying a matching tag for the word under the cursor
814 : try
815 : exe "ptag " . w
816 : catch
817 : return
818 : endtry
819 :
820 : silent! wincmd P " jump to preview window
821 : if &previewwindow " if we really get there...
822 : if has("folding")
823 : silent! .foldopen " don't want a closed fold
824 : endif
825 : call search("$", "b") " to end of previous line
826 : let w = substitute(w, '\\', '\\\\', "")
827 : call search('\<\V' . w . '\>') " position cursor on match
828 : " Add a match highlight to the word at this position
829 : hi previewWord term=bold ctermbg=green guibg=green
830 : exe 'match previewWord "\%' . line(".") . 'l\%' . col(".") . 'c\k*"'
831 : wincmd p " back to old window
832 : endif
833 : endif
834 :endfun
835
836==============================================================================
83711. Using hidden buffers *buffer-hidden*
838
839A hidden buffer is not displayed in a window, but is still loaded into memory.
840This makes it possible to jump from file to file, without the need to read or
841write the file every time you get another buffer in a window.
842{not available when compiled without the |+listcmds| feature}
843
844 *:buffer-!*
845If the option 'hidden' ('hid') is set, abandoned buffers are kept for all
846commands that start editing another file: ":edit", ":next", ":tag", etc. The
847commands that move through the buffer list sometimes make the current buffer
848hidden although the 'hidden' option is not set. This happens when a buffer is
849modified, but is forced (with '!') to be removed from a window, and
850'autowrite' is off or the buffer can't be written.
851
852You can make a hidden buffer not hidden by starting to edit it with any
853command. Or by deleting it with the ":bdelete" command.
854
855The 'hidden' is global, it is used for all buffers. The 'bufhidden' option
856can be used to make an exception for a specific buffer. It can take these
857values:
858 <empty> Use the value of 'hidden'.
859 hide Hide this buffer, also when 'hidden' is not set.
860 unload Don't hide but unload this buffer, also when 'hidden'
861 is set.
862 delete Delete the buffer.
863
864 *hidden-quit*
865When you try to quit Vim while there is a hidden, modified buffer, you will
866get an error message and Vim will make that buffer the current buffer. You
867can then decide to write this buffer (":wq") or quit without writing (":q!").
868Be careful: there may be more hidden, modified buffers!
869
870A buffer can also be unlisted. This means it exists, but it is not in the
871list of buffers. |unlisted-buffer|
872
873
874:files[!] *:files*
875:buffers[!] *:buffers* *:ls*
876:ls[!] Show all buffers. Example:
877
878 1 #h "/test/text" line 1 ~
879 2u "asdf" line 0 ~
Bram Moolenaar81695252004-12-29 20:58:21 +0000880 3 %a+ "version.c" line 1 ~
Bram Moolenaar071d4272004-06-13 20:20:40 +0000881
882 When the [!] is included the list will show unlisted buffers
883 (the term "unlisted" is a bit confusing then...).
884
885 Each buffer has a unique number. That number will not change,
886 so you can always go to a specific buffer with ":buffer N" or
887 "N CTRL-^", where N is the buffer number.
888
889 Indicators (chars in the same column are mutually exclusive):
890 u an unlisted buffer (only displayed when [!] is used)
891 |unlisted-buffer|
892 % the buffer in the current window
893 # the alternate buffer for ":e #" and CTRL-^
894 a an active buffer: it is loaded and visible
895 h a hidden buffer: It is loaded, but currently not
896 displayed in a window |hidden-buffer|
897 - a buffer with 'modifiable' off
898 = a readonly buffer
899 + a modified buffer
900 x a buffer with read errors
901
902 *:bad* *:badd*
903:bad[d] [+lnum] {fname}
904 Add file name {fname} to the buffer list, without loading it.
905 If "lnum" is specified, the cursor will be positioned at that
906 line when the buffer is first entered. Note that other
907 commands after the + will be ignored.
908
909:[N]bd[elete][!] *:bd* *:bdel* *:bdelete* *E516*
910:bd[elete][!] [N]
911 Unload buffer [N] (default: current buffer) and delete it from
912 the buffer list. If the buffer was changed, this fails,
913 unless when [!] is specified, in which case changes are lost.
914 The file remains unaffected. Any windows for this buffer are
915 closed. If buffer [N] is the current buffer, another buffer
916 will be displayed instead. This is the most recent entry in
917 the jump list that points into a loaded buffer.
918 Actually, the buffer isn't completely deleted, it is removed
919 from the buffer list |unlisted-buffer| and option values,
920 variables and mappings/abbreviations for the buffer are
921 cleared.
922
923:bdelete[!] {bufname} *E93* *E94*
924 Like ":bdelete[!] [N]", but buffer given by name. Note that a
925 buffer whose name is a number cannot be referenced by that
926 name; use the buffer number instead. Insert a backslash
927 before a space in a buffer name.
928
929:bdelete[!] N1 N2 ...
930 Do ":bdelete[!]" for buffer N1, N2, etc. The arguments can be
931 buffer numbers or buffer names (but not buffer names that are
932 a number). Insert a backslash before a space in a buffer
933 name.
934
935:N,Mbdelete[!] Do ":bdelete[!]" for all buffers in the range N to M
936 |inclusive|.
937
938:[N]bw[ipeout][!] *:bw* *:bwipe* *:bwipeout* *E517*
939:bw[ipeout][!] {bufname}
940:N,Mbw[ipeout][!]
941:bw[ipeout][!] N1 N2 ...
942 Like |:bdelete|, but really delete the buffer. All marks in
943 this buffer become invalid, option settings are lost, etc.
944 Don't use this unless you know what you are doing.
945
946:[N]bun[load][!] *:bun* *:bunload* *E515*
947:bun[load][!] [N]
948 Unload buffer [N] (default: current buffer). The memory
949 allocated for this buffer will be freed. The buffer remains
950 in the buffer list.
951 If the buffer was changed, this fails, unless when [!] is
952 specified, in which case the changes are lost.
953 Any windows for this buffer are closed. If buffer [N] is the
954 current buffer, another buffer will be displayed instead.
955 This is the most recent entry in the jump list that points
956 into a loaded buffer.
957
958:bunload[!] {bufname}
959 Like ":bunload[!] [N]", but buffer given by name. Note that a
960 buffer whose name is a number cannot be referenced by that
961 name; use the buffer number instead. Insert a backslash
962 before a space in a buffer name.
963
964:N,Mbunload[!] Do ":bunload[!]" for all buffers in the range N to M
965 |inclusive|.
966
967:bunload[!] N1 N2 ...
968 Do ":bunload[!]" for buffer N1, N2, etc. The arguments can be
969 buffer numbers or buffer names (but not buffer names that are
970 a number). Insert a backslash before a space in a buffer
971 name.
972
973:[N]b[uffer][!] [N] *:b* *:bu* *:buf* *:buffer* *E86*
974 Edit buffer [N] from the buffer list. If [N] is not given,
975 the current buffer remains being edited. See |:buffer-!| for
976 [!]. This will also edit a buffer that is not in the buffer
977 list, without setting the 'buflisted' flag.
978
979:[N]b[uffer][!] {filename}
980 Edit buffer for {filename} from the buffer list. See
981 |:buffer-!| for [!]. This will also edit a buffer that is not
982 in the buffer list, without setting the 'buflisted' flag.
983
984:[N]sb[uffer] [N] *:sb* *:sbuffer*
985 Split window and edit buffer [N] from the buffer list. If [N]
986 is not given, the current buffer is edited. Respects the
987 "useopen" setting of 'switchbuf' when splitting. This will
988 also edit a buffer that is not in the buffer list, without
989 setting the 'buflisted' flag.
990
991:[N]sb[uffer] {filename}
992 Split window and edit buffer for {filename} from the buffer
993 list. This will also edit a buffer that is not in the buffer
994 list, without setting the 'buflisted' flag.
995
996 *:bn* *:bnext* *E87*
997:[N]bn[ext][!] [N]
998 Go to [N]th next buffer in buffer list. [N] defaults to one.
999 Wraps around the end of the buffer list.
1000 See |:buffer-!| for [!].
1001 If you are in a help buffer, this takes you to the next help
1002 buffer (if there is one). Similarly, if you are in a normal
1003 (non-help) buffer, this takes you to the next normal buffer.
1004 This is so that if you have invoked help, it doesn't get in
1005 the way when you're browsing code/text buffers. The next three
1006 commands also work like this.
1007
1008 *:sbn* *:sbnext*
1009:[N]sbn[ext] [N]
1010 Split window and go to [N]th next buffer in buffer list.
1011 Wraps around the end of the buffer list. Uses 'switchbuf'
1012
1013:[N]bN[ext][!] [N] *:bN* *:bNext* *:bp* *:bprevious* *E88*
1014:[N]bp[revious][!] [N]
1015 Go to [N]th previous buffer in buffer list. [N] defaults to
1016 one. Wraps around the start of the buffer list.
1017 See |:buffer-!| for [!] and 'switchbuf'.
1018
1019:[N]sbN[ext] [N] *:sbN* *:sbNext* *:sbp* *:sbprevious*
1020:[N]sbp[revious] [N]
1021 Split window and go to [N]th previous buffer in buffer list.
1022 Wraps around the start of the buffer list.
1023 Uses 'switchbuf'.
1024
1025 *:br* *:brewind*
1026:br[ewind][!] Go to first buffer in buffer list. If the buffer list is
1027 empty, go to the first unlisted buffer.
1028 See |:buffer-!| for [!].
1029
1030 *:bf* *:bfirst*
1031:bf[irst] Same as ":brewind".
1032
1033 *:sbr* *:sbrewind*
1034:sbr[ewind] Split window and go to first buffer in buffer list. If the
1035 buffer list is empty, go to the first unlisted buffer.
1036 Respects the 'switchbuf' option.
1037
1038 *:sbf* *:sbfirst*
1039:sbf[irst] Same as ":sbrewind".
1040
1041 *:bl* *:blast*
1042:bl[ast][!] Go to last buffer in buffer list. If the buffer list is
1043 empty, go to the last unlisted buffer.
1044 See |:buffer-!| for [!].
1045
1046 *:sbl* *:sblast*
1047:sbl[ast] Split window and go to last buffer in buffer list. If the
1048 buffer list is empty, go to the last unlisted buffer.
1049 Respects 'switchbuf' option.
1050
1051:[N]bm[odified][!] [N] *:bm* *:bmodified* *E84*
1052 Go to [N]th next modified buffer. Note: this command also
1053 finds unlisted buffers. If there is no modified buffer the
1054 command fails.
1055
1056:[N]sbm[odified] [N] *:sbm* *:sbmodified*
1057 Split window and go to [N]th next modified buffer.
1058 Respects 'switchbuf' option.
1059 Note: this command also finds buffers not in the buffer list.
1060
1061:[N]unh[ide] [N] *:unh* *:unhide* *:sun* *:sunhide*
1062:[N]sun[hide] [N]
1063 Rearrange the screen to open one window for each loaded buffer
1064 in the buffer list. When a count is given, this is the
1065 maximum number of windows to open.
1066
1067:[N]ba[ll] [N] *:ba* *:ball* *:sba* *:sball*
1068:[N]sba[ll] [N] Rearrange the screen to open one window for each buffer in
1069 the buffer list. When a count is given, this is the maximum
1070 number of windows to open. 'winheight' also limits the number
1071 of windows opened ('winwidth' if |:vertical| was prepended).
1072 Buf/Win Enter/Leave autocommands are not executed for the new
1073 windows here, that's only done when they are really entered.
1074
1075Note: All the commands above that start editing another buffer, keep the
1076'readonly' flag as it was. This differs from the ":edit" command, which sets
1077the 'readonly' flag each time the file is read.
1078
1079==============================================================================
108012. Special kinds of buffers *special-buffers*
1081
1082Instead of containing the text of a file, buffers can also be used for other
1083purposes. A few options can be set to change the behavior of a buffer:
1084 'bufhidden' what happens when the buffer is no longer displayed
1085 in a window.
1086 'buftype' what kind of a buffer this is
1087 'swapfile' whether the buffer will have a swap file
1088 'buflisted' buffer shows up in the buffer list
1089
1090A few useful kinds of a buffer:
1091
1092quickfix Used to contain the error list. See |:cwindow|. This command
1093 sets the 'buftype' option to "quickfix". You are not supposed
1094 to change this! 'swapfile' is off.
1095
1096help Contains a help file. Will only be created with the |:help|
1097 command. The flag that indicates a help buffer is internal
1098 and can't be changed. The 'buflisted' option will be reset
1099 for a help buffer.
1100
1101directory Displays directory contents. Used by the |file-explorer|
1102 plugin. The buffer is created with these settings: >
1103 :set buftype=nowrite
1104 :set bufhidden=delete
1105 :set noswapfile
1106< The buffer name is the name of the directory and is adjusted
1107 when using the |:cd| command.
1108
1109scratch Contains text that can be discarded at any time. It is kept
1110 when closing the window, it must be deleted explicitly.
1111 Settings: >
1112 :set buftype=nofile
1113 :set bufhidden=hide
1114 :set noswapfile
1115< The buffer name can be used to identify the buffer.
1116
1117 *unlisted-buffer*
1118unlisted The buffer is not in the buffer list. It is not used for
1119 normal editing, but to show a help file, remember a file name
1120 or marks. The ":bdelete" command will also set this option,
1121 thus it doesn't completely delete the buffer. Settings: >
1122 :set nobuflisted
1123<
1124
1125 vim:tw=78:ts=8:ft=help:norl: