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