windows.txt (60497B)
1 *windows.txt* For Vim version 9.2. Last change: 2026 Aug 27 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7 Editing with multiple windows and buffers. *windows* *buffers* 8 9 The commands which have been added to use multiple windows and buffers are 10 explained here. Additionally, there are explanations for commands that work 11 differently when used in combination with more than one window. 12 13 The basics are explained in chapter 7 and 8 of the user manual |usr_07.txt| 14 |usr_08.txt|. 15 16 1. Introduction |windows-intro| 17 2. Starting Vim |windows-starting| 18 3. Opening and closing a window |opening-window| 19 4. Moving cursor to other windows |window-move-cursor| 20 5. Moving windows around |window-moving| 21 6. Window resizing |window-resize| 22 7. Argument and buffer list commands |buffer-list| 23 8. Do a command in all buffers or windows |list-repeat| 24 9. Tag or file name under the cursor |window-tag| 25 10. The preview window |preview-window| 26 11. Using hidden buffers |buffer-hidden| 27 12. Special kinds of buffers |special-buffers| 28 29 {not able to use multiple windows when the |+windows| feature was disabled at 30 compile time} 31 32 ============================================================================== 33 1. Introduction *windows-intro* *window* 34 35 Summary: 36 A buffer is the in-memory text of a file. 37 A window is a viewport on a buffer. 38 A tab page is a collection of windows. 39 40 A window is a viewport onto a buffer. You can use multiple windows on one 41 buffer, or several windows on different buffers. 42 43 A buffer is a file loaded into memory for editing. The original file remains 44 unchanged until you write the buffer to the file. 45 46 A buffer can be in one of three states: 47 48 *active-buffer* 49 active: The buffer is displayed in a window. If there is a file for this 50 buffer, it has been read into the buffer. The buffer may have been 51 modified since then and thus be different from the file. 52 *hidden-buffer* 53 hidden: The buffer is not displayed. If there is a file for this buffer, it 54 has been read into the buffer. Otherwise it's the same as an active 55 buffer, you just can't see it. 56 *inactive-buffer* 57 inactive: The buffer is not displayed and does not contain anything. Options 58 for the buffer are remembered if the file was once loaded. It can 59 contain marks from the |viminfo| file. But the buffer doesn't 60 contain text. 61 62 In a table: 63 64 state displayed loaded ":buffers" ~ 65 in window shows ~ 66 active yes yes 'a' 67 hidden no yes 'h' 68 inactive no no ' ' 69 70 *buffer-reuse* 71 Each buffer has a unique number and the number will not change within a Vim 72 session. The |bufnr()| and |bufname()| functions can be used to convert 73 between a buffer name and the buffer number. There is one exception: if a new 74 empty buffer is created and it is not modified, the buffer will be re-used 75 when loading another file into that buffer. This also means the buffer number 76 will not change. 77 78 The main Vim window can hold several split windows. There are also tab pages 79 |tab-page|, each of which can hold multiple windows. 80 81 *window-ID* *winid* *windowid* 82 Each window has a unique identifier called the window ID. This identifier 83 will not change within a Vim session. The |win_getid()| and |win_id2tabwin()| 84 functions can be used to convert between the window/tab number and the 85 identifier. There is also the window number, which may change whenever 86 windows are opened or closed, see |winnr()|. 87 The window number is only valid in one specific tab. The window ID is valid 88 across tabs. For most functions that take a window ID or a window number, the 89 window number only applies to the current tab, while the window ID can refer 90 to a window in any tab. 91 92 93 ============================================================================== 94 2. Starting Vim *windows-starting* 95 96 By default, Vim starts with one window, just like Vi. 97 98 The "-o" and "-O" arguments to Vim can be used to open a window for each file 99 in the argument list. The "-o" argument will split the windows horizontally; 100 the "-O" argument will split the windows vertically. If both "-o" and "-O" 101 are given, the last one encountered will be used to determine the split 102 orientation. For example, this will open three windows, split horizontally: > 103 vim -o file1 file2 file3 104 105 "-oN", where N is a decimal number, opens N windows split horizontally. If 106 there are more file names than windows, only N windows are opened and some 107 files do not get a window. If there are more windows than file names, the 108 last few windows will be editing empty buffers. Similarly, "-ON" opens N 109 windows split vertically, with the same restrictions. 110 111 If there are many file names, the windows will become very small. You might 112 want to set the 'winheight' and/or 'winwidth' options to create a workable 113 situation. 114 115 Buf/Win Enter/Leave |autocommand|s are not executed when opening the new 116 windows and reading the files, that's only done when they are really entered. 117 118 *status-line* 119 A status line will be used to separate windows. The 'laststatus' option tells 120 when the last window also has a status line: 121 'laststatus' = 0 never a status line 122 'laststatus' = 1 status line if there is more than one window 123 'laststatus' = 2 always a status line 124 125 You can change the contents and height of the status line with the 126 'statusline' and 'statuslineopt' options. Both can be local to the window, 127 allowing each window to have a unique status line appearance and height. 128 129 Normally, inversion is used to display the status line. This can be changed 130 with the 's' character in the 'highlight' option. For example, "sb" sets it 131 to bold characters. If no highlighting is used for the status line ("sn"), 132 the '^' character is used for the current window, and '=' for other windows. 133 If the mouse is supported and enabled with the 'mouse' option, a status line 134 can be dragged to resize windows. 135 136 Note: If you expect your status line to be in reverse video and it isn't, 137 check if the 'highlight' option contains "si". In version 3.0, this meant to 138 invert the status line. Now it should be "sr", reverse the status line, as 139 "si" now stands for italic! If italic is not available on your terminal, the 140 status line is inverted anyway; you will only see this problem on terminals 141 that have termcap codes for italics. 142 143 *filler-lines* 144 The lines after the last buffer line in a window are called filler lines. By 145 default, these lines start with a tilde (~) character. The "eob" item in the 146 'fillchars' option can be used to change this character. By default, these 147 characters are highlighted as NonText (|hl-NonText|). The EndOfBuffer 148 highlight group (|hl-EndOfBuffer|) can be used to change the highlighting of 149 the filler characters. 150 151 ============================================================================== 152 3. Opening and closing a window *opening-window* 153 154 CTRL-W s *CTRL-W_s* 155 CTRL-W S *CTRL-W_S* 156 CTRL-W CTRL-S *CTRL-W_CTRL-S* 157 :[N]sp[lit] [++opt] [+cmd] *:sp* *:split* 158 Split current window in two. The result is two viewports on 159 the same file. 160 161 Make the new window N high (default is to use half the height 162 of the current window). Reduces the current window height to 163 create room (and others, if the 'equalalways' option is set, 164 'eadirection' isn't "hor", and one of them is higher than the 165 current or the new window). 166 167 Note: CTRL-S does not work on all terminals and might block 168 further input, use CTRL-Q to get going again. 169 Also see |++opt| and |+cmd|. 170 *E242* *E1159* 171 Be careful when splitting a window in an autocommand, it may 172 mess up the window layout if this happens while making other 173 window layout changes. 174 175 :[N]sp[lit] [++opt] [+cmd] {file} *:split_f* 176 Like |:split| but create a new window and start editing file 177 {file} in it. 178 This behaves almost like a ":split" first, and then an ":edit" 179 command, but the alternate file name in the original window is 180 set to {file}. 181 If [+cmd] is given, execute the command when the file has been 182 loaded |+cmd|. 183 Also see |++opt|. 184 Make new window N high (default is to use half the existing 185 height). Reduces the current window height to create room 186 (and others, if the 'equalalways' option is set). 187 188 CTRL-W CTRL-V *CTRL-W_CTRL-V* 189 CTRL-W v *CTRL-W_v* 190 :[N]vs[plit] [++opt] [+cmd] [file] *:vs* *:vsplit* 191 Like |:split|, but split vertically. The windows will be 192 spread out horizontally if 193 1. a width was not specified, 194 2. 'equalalways' is set, 195 3. 'eadirection' isn't "ver", and 196 4. one of the other windows is wider than the current or new 197 window. 198 If N was given make the new window N columns wide, if 199 possible. 200 Note: In other places CTRL-Q does the same as CTRL-V, but here 201 it doesn't! 202 203 CTRL-W n *CTRL-W_n* 204 CTRL-W CTRL-N *CTRL-W_CTRL-N* 205 :[N]new [++opt] [+cmd] *:new* 206 Create a new window and start editing an empty file in it. 207 Make new window N high (default is to use half the existing 208 height). Reduces the current window height to create room 209 (and others, if the 'equalalways' option is set and 210 'eadirection' isn't "hor"). 211 Also see |++opt| and |+cmd|. 212 If 'fileformats' is not empty, the first format given will be 213 used for the new buffer. If 'fileformats' is empty, the 214 'fileformat' of the current buffer is used. This can be 215 overridden with the |++opt| argument. 216 Autocommands are executed in this order: 217 1. WinLeave for the current window 218 2. WinEnter for the new window 219 3. BufLeave for the current buffer 220 4. BufEnter for the new buffer 221 This behaves like a ":split" first, and then an ":enew" 222 command. 223 224 :[N]new [++opt] [+cmd] {file} 225 Like |:split_f|, create a new window and start editing {file}. 226 227 :[N]vne[w] [++opt] [+cmd] [file] *:vne* *:vnew* 228 Like |:new|, but split vertically. If 'equalalways' is set 229 and 'eadirection' isn't "ver" the windows will be spread out 230 horizontally, unless a width was specified. 231 232 :[N]sv[iew] [++opt] [+cmd] [file] *:sv* *:sview* *splitview* 233 Same as ":split", but set 'readonly' option for this buffer. 234 235 :[N]sf[ind] [++opt] [+cmd] {file} *:sf* *:sfi* *:sfind* *splitfind* 236 Same as ":split", but search for {file} in 'path' like in 237 |:find|. Doesn't split if {file} is not found. 238 239 CTRL-W CTRL-^ *CTRL-W_CTRL-^* *CTRL-W_^* 240 CTRL-W ^ Split the current window in two and edit the alternate file. 241 When a count N is given, split the current window and edit 242 buffer N. Similar to ":sp #" and ":sp #N", but it allows the 243 other buffer to be unnamed. This command matches the behavior 244 of |CTRL-^|, except that it splits a window first. 245 246 *CTRL-W_:* 247 CTRL-W : Does the same as typing |:| - enter a command line. Useful in a 248 terminal window, where all Vim commands must be preceded with 249 CTRL-W or 'termwinkey'. 250 251 Note that the 'splitbelow' and 'splitright' options influence where a new 252 window will appear. 253 *E36* 254 Creating a window will fail if there is not enough room. Every window needs 255 at least one screen line and column, sometimes more. Options 'winminheight' 256 and 'winminwidth' are relevant. 257 258 *:vert* *:vertical* 259 :vert[ical] {cmd} 260 Execute {cmd}. If it contains a command that splits a window, 261 it will be split vertically. For `vertical wincmd =` windows 262 will be equalized only vertically. 263 Doesn't work for |:execute| and |:normal|. 264 265 *:hor* *:horizontal* 266 :hor[izontal] {cmd} 267 Execute {cmd}. Currently only makes a difference for 268 `horizontal wincmd =`, which will equalize windows only 269 horizontally. 270 271 :lefta[bove] {cmd} *:lefta* *:leftabove* 272 :abo[veleft] {cmd} *:abo* *:aboveleft* 273 Execute {cmd}. If it contains a command that splits a window, 274 it will be opened left (vertical split) or above (horizontal 275 split) the current window. Overrules 'splitbelow' and 276 'splitright'. 277 Doesn't work for |:execute| and |:normal|. 278 279 :rightb[elow] {cmd} *:rightb* *:rightbelow* 280 :bel[owright] {cmd} *:bel* *:belowright* 281 Execute {cmd}. If it contains a command that splits a window, 282 it will be opened right (vertical split) or below (horizontal 283 split) the current window. Overrules 'splitbelow' and 284 'splitright'. 285 Doesn't work for |:execute| and |:normal|. 286 287 *:topleft* *E442* 288 :to[pleft] {cmd} 289 Execute {cmd}. If it contains a command that splits a window, 290 it will appear at the top and occupy the full width of the Vim 291 window. When the split is vertical the window appears at the 292 far left and occupies the full height of the Vim window. 293 Doesn't work for |:execute| and |:normal|. 294 295 *:bo* *:botright* 296 :bo[tright] {cmd} 297 Execute {cmd}. If it contains a command that splits a window, 298 it will appear at the bottom and occupy the full width of the 299 Vim window. When the split is vertical the window appears at 300 the far right and occupies the full height of the Vim window. 301 Doesn't work for |:execute| and |:normal|. 302 303 These command modifiers can be combined to make a vertically split window 304 occupy the full height. Example: > 305 :vertical topleft split tags 306 Opens a vertically split, full-height window on the "tags" file at the far 307 left of the Vim window. 308 309 310 Closing a window 311 ---------------- 312 313 :q[uit] 314 :{count}q[uit] *:count_quit* 315 CTRL-W q *CTRL-W_q* 316 CTRL-W CTRL-Q *CTRL-W_CTRL-Q* 317 Without {count}: Quit the current window. If {count} is 318 given quit the {count} window. 319 *edit-window* 320 When quitting the last edit window (not counting help or 321 preview windows), exit Vim. 322 323 When 'hidden' is set, and there is only one window for the 324 current buffer, it becomes hidden. When 'hidden' is not set, 325 and there is only one window for the current buffer, and the 326 buffer was changed, the command fails. 327 328 (Note: CTRL-Q does not work on all terminals). 329 330 If [count] is greater than the last window number the last 331 window will be closed: > 332 :1quit " quit the first window 333 :$quit " quit the last window 334 :9quit " quit the last window 335 " if there are fewer than 9 windows opened 336 :-quit " quit the previous window 337 :+quit " quit the next window 338 :+2quit " quit the second next window 339 < 340 When closing a help window, and this is not the only window, 341 Vim will try to restore the previous window layout, see 342 |:helpclose|. 343 344 :q[uit]! 345 :{count}q[uit]! 346 Without {count}: Quit the current window. If {count} is 347 given quit the {count} window. 348 349 If this was the last window for a buffer, any changes to that 350 buffer are lost. When quitting the last window (not counting 351 help windows), exit Vim. The contents of the buffer are lost, 352 even when 'hidden' is set. 353 354 :clo[se][!] 355 :{count}clo[se][!] 356 CTRL-W c *CTRL-W_c* *:clo* *:close* 357 Without {count}: Close the current window. If {count} is 358 given close the {count} window. 359 360 When the 'hidden' option is set, or when the buffer was 361 changed and the [!] is used, the buffer becomes hidden (unless 362 there is another window editing it). 363 364 When there is only one |edit-window| in the current tab page 365 and there is another tab page, this closes the current tab 366 page. |tab-page|. 367 368 This command fails when: *E444* 369 - There is only one window on the screen. 370 - When 'hidden' is not set, [!] is not used, the buffer has 371 changes, and there is no other window on this buffer. 372 Changes to the buffer are not written and won't get lost, so 373 this is a "safe" command. 374 375 CTRL-W CTRL-C *CTRL-W_CTRL-C* 376 You might have expected that CTRL-W CTRL-C closes the current 377 window, but that does not work, because the CTRL-C cancels the 378 command. 379 380 *:hide* 381 :hid[e] 382 :{count}hid[e] 383 Without {count}: Quit the current window, unless it is the 384 last window on the screen. 385 If {count} is given quit the {count} window. 386 387 The buffer becomes hidden (unless there is another window 388 editing it or 'bufhidden' is "unload", "delete" or "wipe"). 389 If the window is the last one in the current tab page the tab 390 page is closed. |tab-page| 391 392 The value of 'hidden' is irrelevant for this command. Changes 393 to the buffer are not written and won't get lost, so this is a 394 "safe" command. 395 396 :hid[e] {cmd} Execute {cmd} with 'hidden' set. The previous value of 397 'hidden' is restored after {cmd} has been executed. 398 Example: > 399 :hide edit Makefile 400 < This will edit "Makefile", and hide the current buffer if it 401 has any changes. 402 403 :on[ly][!] 404 :{count}on[ly][!] 405 CTRL-W o *CTRL-W_o* *E445* 406 CTRL-W CTRL-O *CTRL-W_CTRL-O* *:on* *:only* 407 Make the current window the only one on the screen. All other 408 windows are closed. For {count} see the `:quit` command 409 above |:count_quit|. 410 411 When the 'hidden' option is set, all buffers in closed windows 412 become hidden. 413 414 When 'hidden' is not set, and the 'autowrite' option is set, 415 modified buffers are written. Otherwise, windows that have 416 buffers that are modified are not removed, unless the [!] is 417 given, then they become hidden. But modified buffers are 418 never abandoned, so changes cannot get lost. 419 420 ============================================================================== 421 4. Moving cursor to other windows *window-move-cursor* 422 423 CTRL-W <Down> *CTRL-W_<Down>* 424 CTRL-W CTRL-J *CTRL-W_CTRL-J* *CTRL-W_j* 425 CTRL-W j Move cursor to Nth window below current one. Uses the cursor 426 position to select between alternatives. 427 428 CTRL-W <Up> *CTRL-W_<Up>* 429 CTRL-W CTRL-K *CTRL-W_CTRL-K* *CTRL-W_k* 430 CTRL-W k Move cursor to Nth window above current one. Uses the cursor 431 position to select between alternatives. 432 433 CTRL-W <Left> *CTRL-W_<Left>* 434 CTRL-W CTRL-H *CTRL-W_CTRL-H* 435 CTRL-W <BS> *CTRL-W_<BS>* *CTRL-W_h* 436 CTRL-W h Move cursor to Nth window left of current one. Uses the 437 cursor position to select between alternatives. 438 439 CTRL-W <Right> *CTRL-W_<Right>* 440 CTRL-W CTRL-L *CTRL-W_CTRL-L* *CTRL-W_l* 441 CTRL-W l Move cursor to Nth window right of current one. Uses the 442 cursor position to select between alternatives. 443 444 CTRL-W w *CTRL-W_w* *CTRL-W_CTRL-W* 445 CTRL-W CTRL-W Without count: move cursor to window below/right of the 446 current one. If there is no window below or right, go to 447 top-left window. 448 With count: go to Nth window (windows are numbered from 449 top-left to bottom-right). To obtain the window number see 450 |bufwinnr()| and |winnr()|. When N is larger than the number 451 of windows go to the last window. 452 453 *CTRL-W_W* 454 CTRL-W W Without count: move cursor to window above/left of current 455 one. If there is no window above or left, go to bottom-right 456 window. With count: go to Nth window, like with CTRL-W w. 457 458 CTRL-W t *CTRL-W_t* *CTRL-W_CTRL-T* 459 CTRL-W CTRL-T Move cursor to top-left window. 460 461 CTRL-W b *CTRL-W_b* *CTRL-W_CTRL-B* 462 CTRL-W CTRL-B Move cursor to bottom-right window. 463 464 CTRL-W p *CTRL-W_p* *CTRL-W_CTRL-P* 465 CTRL-W CTRL-P Go to previous (last accessed) window. 466 467 *CTRL-W_P* *E441* 468 CTRL-W P Go to preview window. When there is no preview window this is 469 an error. 470 {not available when compiled without the |+quickfix| feature} 471 472 If Visual mode is active and the new window is not for the same buffer, the 473 Visual mode is ended. If the window is on the same buffer, the cursor 474 position is set to keep the same Visual area selected. 475 476 *:winc* *:wincmd* 477 These commands can also be executed with ":wincmd": 478 479 :[count]winc[md] {arg} 480 Like executing CTRL-W [count] {arg}. Example: > 481 :wincmd j 482 < Moves to the window below the current one. 483 This command is useful when a Normal mode cannot be used (for 484 the |CursorHold| autocommand event). Or when a Normal mode 485 command is inconvenient. 486 The count can also be a window number. Example: > 487 :exe nr .. "wincmd w" 488 < This goes to window "nr". 489 490 Note: All CTRL-W commands can also be executed with |:wincmd|, for those 491 places where a Normal mode command can't be used or is inconvenient (e.g. 492 in a browser-based terminal). 493 494 ============================================================================== 495 5. Moving windows around *window-moving* 496 497 CTRL-W r *CTRL-W_r* *CTRL-W_CTRL-R* *E443* 498 CTRL-W CTRL-R Rotate windows downwards/rightwards. The first window becomes 499 the second one, the second one becomes the third one, etc. 500 The last window becomes the first window. The cursor remains 501 in the same window. 502 This only works within the row or column of windows that the 503 current window is in. 504 505 *CTRL-W_R* 506 CTRL-W R Rotate windows upwards/leftwards. The second window becomes 507 the first one, the third one becomes the second one, etc. The 508 first window becomes the last window. The cursor remains in 509 the same window. 510 This only works within the row or column of windows that the 511 current window is in. 512 513 CTRL-W x *CTRL-W_x* *CTRL-W_CTRL-X* 514 CTRL-W CTRL-X Without count: Exchange current window with next one. If 515 there is no next window, exchange with previous window. 516 With count: Exchange current window with Nth window (first 517 window is 1). The cursor is put in the other window. 518 When vertical and horizontal window splits are mixed, the 519 exchange is only done in the row or column of windows that the 520 current window is in. 521 522 The following commands can be used to change the window layout. For example, 523 when there are two vertically split windows, CTRL-W K will change that in 524 horizontally split windows. CTRL-W H does it the other way around. 525 526 *CTRL-W_K* 527 CTRL-W K Move the current window to be at the very top, using the full 528 width of the screen. This works like `:topleft split`, except 529 it is applied to the current window and no new window is 530 created. 531 532 *CTRL-W_J* 533 CTRL-W J Move the current window to be at the very bottom, using the 534 full width of the screen. This works like `:botright split`, 535 except it is applied to the current window and no new window 536 is created. 537 538 *CTRL-W_H* 539 CTRL-W H Move the current window to be at the far left, using the 540 full height of the screen. This works like 541 `:vert topleft split`, except it is applied to the current 542 window and no new window is created. 543 544 *CTRL-W_L* 545 CTRL-W L Move the current window to be at the far right, using the full 546 height of the screen. This works like `:vert botright split`, 547 except it is applied to the current window and no new window 548 is created. 549 550 *CTRL-W_T* 551 CTRL-W T Move the current window to a new tab page. This fails if 552 there is only one window in the current tab page. 553 This works like `:tab split`, except the previous window is 554 closed. 555 When a count is specified the new tab page will be opened 556 before the tab page with this index. Otherwise it comes after 557 the current tab page. 558 559 ============================================================================== 560 6. Window resizing *window-resize* 561 562 *CTRL-W_=* 563 CTRL-W = Make all windows (almost) equally high and wide, but use 564 'winheight' and 'winwidth' for the current window. 565 Windows with 'winfixheight' set keep their height and windows 566 with 'winfixwidth' set keep their width. 567 To equalize only vertically (make window equally high) use 568 `vertical wincmd =`. 569 To equalize only horizontally (make window equally wide) use 570 `horizontal wincmd =`. 571 572 :res[ize] -N *:res* *:resize* *CTRL-W_-* 573 CTRL-W - Decrease current window height by N (default 1). 574 If used after |:vertical|: decrease width by N. 575 576 :res[ize] +N *CTRL-W_+* 577 CTRL-W + Increase current window height by N (default 1). 578 If used after |:vertical|: increase width by N. 579 580 :res[ize] [N] 581 CTRL-W CTRL-_ *CTRL-W_CTRL-_* *CTRL-W__* 582 CTRL-W _ Set current window height to N (default: highest possible). 583 584 :{winnr}res[ize] [+-]N 585 Like `:resize` above, but apply the size to window {winnr} 586 instead of the current window. 587 588 z{nr}<CR> Set current window height to {nr}. 589 590 *CTRL-W_<* 591 CTRL-W < Decrease current window width by N (default 1). 592 593 *CTRL-W_>* 594 CTRL-W > Increase current window width by N (default 1). 595 596 :vert[ical] res[ize] [N] *:vertical-resize* *CTRL-W_bar* 597 CTRL-W | Set current window width to N (default: widest possible). 598 599 You can also resize a window by dragging a status line up or down with the 600 mouse. Or by dragging a vertical separator line left or right. This only 601 works if the version of Vim that is being used supports the mouse and the 602 'mouse' option has been set to enable it. 603 604 The option 'winheight' ('wh') is used to set the minimal window height of the 605 current window. This option is used each time another window becomes the 606 current window. If the option is '0', it is disabled. Set 'winheight' to a 607 very large value, e.g., '9999', to make the current window always fill all 608 available space. Set it to a reasonable value, e.g., '10', to make editing in 609 the current window comfortable. 610 611 The equivalent 'winwidth' ('wiw') option is used to set the minimal width of 612 the current window. 613 614 When the option 'equalalways' ('ea') is set, all the windows are automatically 615 made the same size after splitting or closing a window. If you don't set this 616 option, splitting a window will reduce the size of the current window and 617 leave the other windows the same. When closing a window, the extra lines are 618 given to the window above it. 619 620 The 'eadirection' option limits the direction in which the 'equalalways' 621 option is applied. The default "both" resizes in both directions. When the 622 value is "ver" only the heights of windows are equalized. Use this when you 623 have manually resized a vertically split window and want to keep this width. 624 Likewise, "hor" causes only the widths of windows to be equalized. 625 626 The option 'cmdheight' ('ch') is used to set the height of the command-line. 627 If you are annoyed by the |hit-enter| prompt for long messages, set this 628 option to 2 or 3. 629 630 If there is only one window, resizing that window will also change the command 631 line height. If there are several windows, resizing the current window will 632 also change the height of the window below it (and sometimes the window above 633 it). 634 635 The minimal height and width of a window is set with 'winminheight' and 636 'winminwidth'. These are hard values, a window will never become smaller. 637 638 639 WinScrolled and WinResized autocommands ~ 640 *win-scrolled-resized* 641 If you want to get notified of changes in window sizes, the |WinResized| 642 autocommand event can be used. 643 If you want to get notified of text in windows scrolling vertically or 644 horizontally, the |WinScrolled| autocommand event can be used. This will also 645 trigger in window size changes. 646 Exception: the events will not be triggered when the text scrolls for 647 'incsearch'. 648 *WinResized-event* 649 The |WinResized| event is triggered after updating the display, several 650 windows may have changed size then. A list of the IDs of windows that changed 651 since last time is provided in the v:event.windows variable, for example: 652 [1003, 1006] 653 *WinScrolled-event* 654 The |WinScrolled| event is triggered after |WinResized|, and also if a window 655 was scrolled. That can be vertically (the text at the top of the window 656 changed) or horizontally (when 'wrap' is off or when the first displayed part 657 of the first line changes). Note that |WinScrolled| will trigger many more 658 times than |WinResized|, it may slow down editing a bit. 659 660 The information provided by |WinScrolled| is a dictionary for each window that 661 has changes, using the window ID as the key, and a total count of the changes 662 with the key "all". Example value for |v:event| (|Vim9| syntax): > 663 { 664 all: {width: 0, height: 2, leftcol: 0, skipcol: 0, topline: 1, topfill: 0}, 665 1003: {width: 0, height: -1, leftcol: 0, skipcol: 0, topline: 0, topfill: 0}, 666 1006: {width: 0, height: 1, leftcol: 0, skipcol: 0, topline: 1, topfill: 0}, 667 } 668 669 Note that the "all" entry has the absolute values of the individual windows 670 accumulated. 671 672 If you need more information about what changed, or you want to "debounce" the 673 events (not handle every event to avoid doing too much work), you may want to 674 use the `winlayout()` and `getwininfo()` functions. 675 676 |WinScrolled| and |WinResized| do not trigger when the first autocommand is 677 added, only after the first scroll or resize. They may trigger when switching 678 to another tab page. 679 680 The commands executed are expected to not cause window size or scroll changes. 681 If this happens anyway, the event will trigger again very soon. In other 682 words: Just before triggering the event, the current sizes and scroll 683 positions are stored and used to decide whether there was a change. 684 *E1312* 685 It is not allowed to change the window layout here (split, close or move 686 windows). 687 688 ============================================================================== 689 7. Argument and buffer list commands *buffer-list* 690 691 args list buffer list meaning ~ 692 1. :[N]argument [N] 11. :[N]buffer [N] to arg/buf N 693 2. :[N]next [file ..] 12. :[N]bnext [N] to Nth next arg/buf 694 3. :[N]Next [N] 13. :[N]bNext [N] to Nth previous arg/buf 695 4. :[N]previous [N] 14. :[N]bprevious [N] to Nth previous arg/buf 696 5. :rewind / :first 15. :brewind / :bfirst to first arg/buf 697 6. :last 16. :blast to last arg/buf 698 7. :all 17. :ball edit all args/buffers 699 18. :unhide edit all loaded buffers 700 19. :[N]bmod [N] to Nth modified buf 701 702 split & args list split & buffer list meaning ~ 703 21. :[N]sargument [N] 31. :[N]sbuffer [N] split + to arg/buf N 704 22. :[N]snext [file ..] 32. :[N]sbnext [N] split + to Nth next arg/buf 705 23. :[N]sNext [N] 33. :[N]sbNext [N] split + to Nth previous arg/buf 706 24. :[N]sprevious [N] 34. :[N]sbprevious [N] split + to Nth previous arg/buf 707 25. :srewind / :sfirst 35. :sbrewind / :sbfirst split + to first arg/buf 708 26. :slast 36. :sblast split + to last arg/buf 709 27. :sall 37. :sball edit all args/buffers 710 38. :sunhide edit all loaded buffers 711 39. :[N]sbmod [N] split + to Nth modified buf 712 713 40. :args list of arguments 714 41. :buffers list of buffers 715 716 The meaning of [N] depends on the command: 717 [N] is the number of buffers to go forward/backward on 2/12/22/32, 718 3/13/23/33, and 4/14/24/34 719 [N] is an argument number, defaulting to current argument, for 1 and 21 720 [N] is a buffer number, defaulting to current buffer, for 11 and 31 721 [N] is a count for 19 and 39 722 723 Note: ":next" is an exception, because it must accept a list of file names 724 for compatibility with Vi. 725 726 727 The argument list and multiple windows 728 -------------------------------------- 729 730 The current position in the argument list can be different for each window. 731 Remember that when doing ":e file", the position in the argument list stays 732 the same, but you are not editing the file at that position. To indicate 733 this, the file message (and the title, if you have one) shows 734 "(file (N) of M)", where "(N)" is the current position in the file list, and 735 "M" the number of files in the file list. 736 737 All the entries in the argument list are added to the buffer list. Thus, you 738 can also get to them with the buffer list commands, like ":bnext". 739 740 :[N]al[l][!] [N] *:al* *:all* *:sal* *:sall* 741 :[N]sal[l][!] [N] 742 Rearrange the screen to open one window for each argument. 743 All other windows are closed. When a count is given, this is 744 the maximum number of windows to open. 745 With the |:tab| modifier open a tab page for each argument. 746 When there are more arguments than 'tabpagemax' further ones 747 become split windows in the last tab page. 748 When the 'hidden' option is set, all buffers in closed windows 749 become hidden. 750 When 'hidden' is not set, and the 'autowrite' option is set, 751 modified buffers are written. Otherwise, windows that have 752 buffers that are modified are not removed, unless the [!] is 753 given, then they become hidden. But modified buffers are 754 never abandoned, so changes cannot get lost. 755 [N] is the maximum number of windows to open. 'winheight' 756 also limits the number of windows opened ('winwidth' if 757 |:vertical| was prepended). 758 Buf/Win Enter/Leave autocommands are not executed for the new 759 windows here, that's only done when they are really entered. 760 If autocommands change the window layout while this command is 761 busy an error will be given. *E249* 762 763 :[N]sa[rgument][!] [++opt] [+cmd] [N] *:sa* *:sargument* 764 Short for ":split | argument [N]": split window and go to Nth 765 argument. But when there is no such argument, the window is 766 not split. Also see |++opt| and |+cmd|. 767 768 :[N]sn[ext][!] [++opt] [+cmd] [file ..] *:sn* *:snext* 769 Short for ":split | [N]next": split window and go to Nth next 770 argument. But when there is no next file, the window is not 771 split. Also see |++opt| and |+cmd|. 772 773 :[N]spr[evious][!] [++opt] [+cmd] [N] *:spr* *:sprevious* 774 :[N]sN[ext][!] [++opt] [+cmd] [N] *:sN* *:sNext* 775 Short for ":split | [N]Next": split window and go to Nth 776 previous argument. But when there is no previous file, the 777 window is not split. Also see |++opt| and |+cmd|. 778 779 *:sre* *:srewind* 780 :sre[wind][!] [++opt] [+cmd] 781 Short for ":split | rewind": split window and go to first 782 argument. But when there is no argument list, the window is 783 not split. Also see |++opt| and |+cmd|. 784 785 *:sfir* *:sfirst* 786 :sfir[st] [++opt] [+cmd] 787 Same as ":srewind". 788 789 *:sla* *:slast* 790 :sla[st][!] [++opt] [+cmd] 791 Short for ":split | last": split window and go to last 792 argument. But when there is no argument list, the window is 793 not split. Also see |++opt| and |+cmd|. 794 795 *:dr* *:drop* 796 :dr[op] [++opt] [+cmd] {file} .. 797 Edit the first {file} in a window. 798 - If the file is already open in a window change to that 799 window. 800 - If the file is not open in a window edit the file in the 801 current window. If the current buffer can't be |abandon|ed, 802 the window is split first. 803 - Windows that are not in the argument list or are not full 804 width will be closed if possible. 805 The |argument-list| is set, like with the |:next| command. 806 The purpose of this command is that it can be used from a 807 program that wants Vim to edit another file, e.g., a debugger. 808 When using the |:tab| modifier each argument is opened in a 809 tab page. The last window is used if it's empty. 810 Also see |++opt| and |+cmd|. 811 812 ============================================================================== 813 8. Do a command in all buffers or windows *list-repeat* 814 815 *:windo* 816 :[range]windo {cmd} Execute {cmd} in each window or if [range] is given 817 only in windows for which the window number lies in 818 the [range]. It works like doing this: > 819 CTRL-W t 820 :{cmd} 821 CTRL-W w 822 :{cmd} 823 etc. 824 < This only operates in the current tab page. 825 When an error is detected on one window, further 826 windows will not be visited. 827 The last window (or where an error occurred) becomes 828 the current window. 829 {cmd} can contain '|' to concatenate several commands. 830 {cmd} must not open or close windows or reorder them. 831 832 Also see |:tabdo|, |:argdo|, |:bufdo|, |:cdo|, |:ldo|, 833 |:cfdo| and |:lfdo| 834 835 *:bufdo* 836 :[range]bufdo[!] {cmd} Execute {cmd} in each buffer in the buffer list or if 837 [range] is given only for buffers for which their 838 buffer number is in the [range]. It works like doing 839 this: > 840 :bfirst 841 :{cmd} 842 :bnext 843 :{cmd} 844 etc. 845 < When the current file can't be |abandon|ed and the [!] 846 is not present, the command fails. 847 When an error is detected on one buffer, further 848 buffers will not be visited. 849 Unlisted buffers are skipped. 850 The last buffer (or where an error occurred) becomes 851 the current buffer. 852 {cmd} can contain '|' to concatenate several commands. 853 {cmd} must not delete buffers or add buffers to the 854 buffer list. 855 Note: While this command is executing, the Syntax 856 autocommand event is disabled by adding it to 857 'eventignore'. This considerably speeds up editing 858 each buffer. 859 860 Also see |:tabdo|, |:argdo|, |:windo|, |:cdo|, |:ldo|, 861 |:cfdo| and |:lfdo| 862 863 Examples: > 864 865 :windo set nolist foldcolumn=0 | normal! zn 866 867 This resets the 'list' option and disables folding in all windows. > 868 869 :bufdo set fileencoding= | update 870 871 This resets the 'fileencoding' in each buffer and writes it if this changed 872 the buffer. The result is that all buffers will use the 'encoding' encoding 873 (if conversion succeeds). 874 875 ============================================================================== 876 9. Tag or file name under the cursor *window-tag* 877 878 *:sta* *:stag* 879 :sta[g][!] [tagname] 880 Does ":tag[!] [tagname]" and splits the window for the found 881 tag. Refer to 'switchbuf' to jump to a tag in a vertically 882 split window or a new tab page. See also |:tag|. 883 884 CTRL-W ] *CTRL-W_]* *CTRL-W_CTRL-]* 885 CTRL-W CTRL-] Split current window in two. Use identifier under cursor as a 886 tag and jump to it in the new upper window. 887 In Visual mode uses the Visually selected text as a tag. 888 Make new window N high. Refer to 'switchbuf' to jump to a tag 889 in a vertically split window or a new tab page. 890 891 *CTRL-W_g]* 892 CTRL-W g ] Split current window in two. Use identifier under cursor as a 893 tag and perform ":tselect" on it in the new upper window. 894 In Visual mode uses the Visually selected text as a tag. 895 Make new window N high. 896 897 *CTRL-W_g_CTRL-]* 898 CTRL-W g CTRL-] Split current window in two. Use identifier under cursor as a 899 tag and perform ":tjump" on it in the new upper window. 900 In Visual mode uses the Visually selected text as a tag. 901 Make new window N high. 902 903 CTRL-W f *CTRL-W_f* *CTRL-W_CTRL-F* 904 CTRL-W CTRL-F Split current window in two. Edit file name under cursor. 905 Like ":split gf", but window isn't split if the file does not 906 exist. 907 Uses the 'path' variable as a list of directory names where to 908 look for the file. Also the path for current file is 909 used to search for the file name. 910 If the name is a hypertext link that looks like 911 "type://machine/path", only "/path" is used. 912 If a count is given, the count'th matching file is edited. 913 914 CTRL-W F *CTRL-W_F* 915 Split current window in two. Edit file name under cursor and 916 jump to the line number following the file name. See |gF| for 917 details on how the line number is obtained. 918 919 CTRL-W gf *CTRL-W_gf* 920 Open a new tab page and edit the file name under the cursor. 921 Like "tab split" and "gf", but the new tab page isn't created 922 if the file does not exist. 923 924 CTRL-W gF *CTRL-W_gF* 925 Open a new tab page and edit the file name under the cursor 926 and jump to the line number following the file name. Like 927 "tab split" and "gF", but the new tab page isn't created if 928 the file does not exist. 929 930 CTRL-W gt *CTRL-W_gt* 931 Go to next tab page, same as `gt`. 932 933 CTRL-W gT *CTRL-W_gT* 934 Go to previous tab page, same as `gT`. 935 936 Also see |CTRL-W_CTRL-I|: open window for an included file that includes 937 the keyword under the cursor. 938 939 ============================================================================== 940 10. The preview window *preview-window* 941 942 The preview window is a special window to show (preview) another file. It is 943 normally a small window used to show an include file or definition of a 944 function. 945 {not available when compiled without the |+quickfix| feature} 946 947 There can be only one preview window (per tab page). It is created with one 948 of the commands below. The 'previewheight' option can be set to specify the 949 height of the preview window when it's opened. The 'previewwindow' option is 950 set in the preview window to be able to recognize it. The 'winfixheight' 951 option is set to have it keep the same height when opening/closing other 952 windows. 953 *preview-popup* 954 Alternatively, a popup window can be used by setting the 'previewpopup' 955 option. When set, it overrules the 'previewwindow' and 'previewheight' 956 settings. The option is a comma-separated list of values: 957 border border style (see 'pumborder') 958 borderhighlight highlight group for the popup border characters 959 close show close button: "on" (default) or "off", and if 960 the value is "on", it must be set after border. 961 height maximum height of the popup 962 highlight highlight group of the popup (default is Pmenu) 963 opacity opacity percentage 0-100 (default 100, fully opaque). 964 When less than 100, content beneath the popup shows 965 through. 966 resize show resize handle: "on" (default) or "off" 967 shadow "off" (default) or "on" using |hl-PmenuShadow| 968 width maximum width of the popup 969 970 Example: > 971 :set previewpopup=height:10,width:60 972 :set previewpopup=border:single,borderhighlight:PmenuBorder 973 :set previewpopup=border:custom:─;│;─;│;┌;┐;┘;└ 974 :set previewpopup=border:round,opacity:80 975 976 A few peculiarities: 977 - If the file is in a buffer already, it will be re-used. This will allow for 978 editing the file while it's visible in the popup window. 979 - No ATTENTION dialog will be used, since you can't edit the file in the popup 980 window. However, if you later open the same buffer in a normal window, you 981 may not notice it's edited elsewhere. And when then using ":edit" to 982 trigger the ATTENTION and responding "A" for Abort, the preview window will 983 become empty. 984 985 *:pt* *:ptag* 986 :pt[ag][!] [tagname] 987 Does ":tag[!] [tagname]" and shows the found tag in a 988 "Preview" window without changing the current buffer or cursor 989 position. If a "Preview" window already exists, it is re-used 990 (like a help window is). If a new one is opened, 991 'previewheight' is used for the height of the window. See 992 also |:tag|. 993 See below for an example. |CursorHold-example| 994 Small difference from |:tag|: When [tagname] is equal to the 995 already displayed tag, the position in the matching tag list 996 is not reset. This makes the CursorHold example work after a 997 |:ptnext|. 998 999 CTRL-W z *CTRL-W_z* 1000 CTRL-W CTRL-Z *CTRL-W_CTRL-Z* *:pc* *:pclose* 1001 :pc[lose][!] Close any "Preview" window currently open. When the 'hidden' 1002 option is set, or when the buffer was changed and the [!] is 1003 used, the buffer becomes hidden (unless there is another 1004 window editing it). The command fails if any "Preview" buffer 1005 cannot be closed. See also |:close|. 1006 1007 *:pp* *:ppop* 1008 :[count]pp[op][!] 1009 Does ":[count]pop[!]" in the preview window. See |:pop| and 1010 |:ptag|. 1011 1012 CTRL-W } *CTRL-W_}* 1013 Use identifier under cursor as a tag and perform a :ptag on 1014 it. Make the new Preview window (if required) N high. If N 1015 is not given, 'previewheight' is used. 1016 1017 CTRL-W g } *CTRL-W_g}* 1018 Use identifier under cursor as a tag and perform a :ptjump on 1019 it. Make the new Preview window (if required) N high. If N 1020 is not given, 'previewheight' is used. 1021 1022 *:pb* *:pbuffer* 1023 :[N]pb[uffer][!] [+cmd] [N] 1024 Edit buffer [N] from the buffer list in the preview window. 1025 If [N] is not given, the current buffer remains being edited. 1026 See |:buffer-!| for [!]. This will also edit a buffer that is 1027 not in the buffer list, without setting the 'buflisted' flag. 1028 The notation with single quotes does not work here, 1029 `:pbuffer 12'345'` uses 12'345' as a buffer name. 1030 Also see |+cmd|. 1031 1032 *:ped* *:pedit* 1033 :ped[it][!] [++opt] [+cmd] {file} 1034 Edit {file} in the preview window. The preview window is 1035 opened like with |:ptag|. The current window and cursor 1036 position isn't changed. Useful example: > 1037 :pedit +/fputc /usr/include/stdio.h 1038 < 1039 Also see |++opt| and |+cmd|. 1040 1041 *:ps* *:psearch* 1042 :[range]ps[earch][!] [count] [/]pattern[/] 1043 Works like |:ijump| but shows the found match in the preview 1044 window. The preview window is opened like with |:ptag|. The 1045 current window and cursor position isn't changed. Useful 1046 example: > 1047 :psearch popen 1048 < Like with the |:ptag| command, you can use this to 1049 automatically show information about the word under the 1050 cursor. This is less clever than using |:ptag|, but you don't 1051 need a tags file and it will also find matches in system 1052 include files. Example: > 1053 :au! CursorHold *.[ch] ++nested exe "silent! psearch " .. expand("<cword>") 1054 < Warning: This can be slow. 1055 1056 Example *CursorHold-example* > 1057 1058 :au! CursorHold *.[ch] ++nested exe "silent! ptag " .. expand("<cword>") 1059 1060 This will cause a ":ptag" to be executed for the keyword under the cursor, 1061 when the cursor hasn't moved for the time set with 'updatetime'. The "nested" 1062 makes other autocommands be executed, so that syntax highlighting works in the 1063 preview window. The "silent!" avoids an error message when the tag could not 1064 be found. Also see |CursorHold|. To disable this again: > 1065 1066 :au! CursorHold 1067 1068 A nice addition is to highlight the found tag, avoid the ":ptag" when there 1069 is no word under the cursor, and a few other things: > 1070 1071 :au! CursorHold *.[ch] ++nested call PreviewWord() 1072 :func PreviewWord() 1073 : if &previewwindow " don't do this in the preview window 1074 : return 1075 : endif 1076 : let w = expand("<cword>") " get the word under cursor 1077 : if w =~ '\a' " if the word contains a letter 1078 : 1079 : " Delete any existing highlight before showing another tag 1080 : silent! wincmd P " jump to preview window 1081 : if &previewwindow " if we really get there... 1082 : match none " delete existing highlight 1083 : wincmd p " back to old window 1084 : endif 1085 : 1086 : " Try displaying a matching tag for the word under the cursor 1087 : try 1088 : exe "ptag " .. w 1089 : catch 1090 : return 1091 : endtry 1092 : 1093 : silent! wincmd P " jump to preview window 1094 : if &previewwindow " if we really get there... 1095 : if has("folding") 1096 : silent! .foldopen " don't want a closed fold 1097 : endif 1098 : call search("$", "b") " to end of previous line 1099 : let w = substitute(w, '\\', '\\\\', "") 1100 : call search('\<\V' .. w .. '\>') " position cursor on match 1101 : " Add a match highlight to the word at this position 1102 : hi previewWord term=bold ctermbg=green guibg=green 1103 : exe 'match previewWord "\%' .. line(".") .. 'l\%' .. col(".") .. 'c\k*"' 1104 : wincmd p " back to old window 1105 : endif 1106 : endif 1107 :endfun 1108 1109 ============================================================================== 1110 11. Using hidden buffers *buffer-hidden* 1111 1112 A hidden buffer is not displayed in a window, but is still loaded into memory. 1113 This makes it possible to jump from file to file, without the need to read or 1114 write the file every time you get another buffer in a window. 1115 1116 *:buffer-!* 1117 If the option 'hidden' ('hid') is set, abandoned buffers are kept for all 1118 commands that start editing another file: ":edit", ":next", ":tag", etc. The 1119 commands that move through the buffer list sometimes make the current buffer 1120 hidden although the 'hidden' option is not set. This happens when a buffer is 1121 modified, but is forced (with '!') to be removed from a window, and 1122 'autowrite' is off or the buffer can't be written. 1123 1124 You can make a hidden buffer not hidden by starting to edit it with any 1125 command, or by deleting it with the ":bdelete" command. 1126 1127 The 'hidden' is global, it is used for all buffers. The 'bufhidden' option 1128 can be used to make an exception for a specific buffer. It can take these 1129 values: 1130 <empty> Use the value of 'hidden'. 1131 hide Hide this buffer, also when 'hidden' is not set. 1132 unload Don't hide but unload this buffer, also when 'hidden' 1133 is set. 1134 delete Delete the buffer. 1135 1136 *hidden-quit* 1137 When you try to quit Vim while there is a hidden, modified buffer, you will 1138 get an error message and Vim will make that buffer the current buffer. You 1139 can then decide to write this buffer (":wq") or quit without writing (":q!"). 1140 Be careful: there may be more hidden, modified buffers! 1141 1142 A buffer can also be unlisted. This means it exists, but it is not in the 1143 list of buffers. |unlisted-buffer| 1144 1145 1146 :files[!] [flags] *:files* 1147 :buffers[!] [flags] *:buffers* *:ls* 1148 :ls[!] [flags] 1149 Show all buffers. Example: 1150 1151 1 #h "/test/text" line 1 ~ 1152 2u "asdf" line 0 ~ 1153 3 %a + "version.c" line 1 ~ 1154 1155 When the [!] is included the list will show unlisted buffers 1156 (the term "unlisted" is a bit confusing then...). 1157 1158 Each buffer has a unique number. That number will not change, 1159 thus you can always go to a specific buffer with ":buffer N" 1160 or "N CTRL-^", where N is the buffer number. 1161 1162 For the file name these special values are used: 1163 "[Prompt]" |prompt-buffer| 1164 "[Popup]" buffer of a |popup-window| 1165 "[Scratch]" 'buftype' is "nofile" 1166 "[No Name]" no file name specified 1167 For a |terminal-window| buffer the status is used. 1168 1169 Indicators (chars in the same column are mutually exclusive): 1170 u an unlisted buffer (only displayed when [!] is used) 1171 |unlisted-buffer| 1172 % the buffer in the current window 1173 # the alternate buffer for ":e #" and CTRL-^ 1174 a an active buffer: it is loaded and visible 1175 h a hidden buffer: It is loaded, but currently not 1176 displayed in a window |hidden-buffer| 1177 - a buffer with 'modifiable' off 1178 = a readonly buffer 1179 R a terminal buffer with a running job 1180 F a terminal buffer with a finished job 1181 ? a terminal buffer without a job: `:terminal NONE` 1182 + a modified buffer 1183 x a buffer with read errors 1184 1185 [flags] can be a combination of the following characters, 1186 which restrict the buffers to be listed: 1187 + modified buffers 1188 - buffers with 'modifiable' off 1189 = readonly buffers 1190 a active buffers 1191 u unlisted buffers (overrides the "!") 1192 h hidden buffers 1193 x buffers with a read error 1194 % current buffer 1195 # alternate buffer 1196 R terminal buffers with a running job 1197 F terminal buffers with a finished job 1198 ? terminal buffers without a job: `:terminal NONE` 1199 t show time last used and sort buffers 1200 Combining flags means they are "and"ed together, e.g.: 1201 h+ hidden buffers which are modified 1202 a+ active buffers which are modified 1203 1204 When using |:filter| the pattern is matched against the 1205 displayed buffer name, e.g.: > 1206 filter /\.vim/ ls 1207 < 1208 *:bad* *:badd* 1209 :bad[d] [+lnum] {fname} 1210 Add file name {fname} to the buffer list, without loading it, 1211 if it wasn't listed yet. If the buffer was previously 1212 deleted, not wiped, it will be made listed again. 1213 If "lnum" is specified, the cursor will be positioned at that 1214 line when the buffer is first entered. Note that other 1215 commands after the + will be ignored. 1216 1217 *:balt* 1218 :balt [+lnum] {fname} 1219 Like `:badd` and also set the alternate file for the current 1220 window to {fname}. 1221 1222 :[N]bd[elete][!] *:bd* *:bdel* *:bdelete* *E516* 1223 :bd[elete][!] [N] 1224 Unload buffer [N] (default: current buffer) and delete it from 1225 the buffer list. If the buffer was changed, this fails, 1226 unless [!] is specified, in which case changes are lost. 1227 The file remains unaffected. Any windows for this buffer are 1228 closed. If buffer [N] is the current buffer, another buffer 1229 will be displayed instead. This is the most recent entry in 1230 the jump list that points into a loaded buffer. 1231 1232 Actually, the buffer isn't completely deleted, it is removed 1233 from the buffer list |unlisted-buffer| and option values, 1234 variables and mappings/abbreviations for the buffer are 1235 cleared. If [N] is the last listed buffer in a window (i.e., 1236 there is no other listed buffer to switch to), the buffer is 1237 emptied instead of being unloaded. The window is not closed, 1238 and the buffer may be reused as a new buffer |buffer-reuse|. 1239 This ensures every window always has a valid buffer. 1240 1241 Examples: > 1242 :.,$-bdelete " delete buffers from the current one to 1243 " last but one 1244 :%bdelete " delete all buffers 1245 < 1246 1247 :bd[elete][!] {bufname} *E93* *E94* 1248 Like ":bdelete[!] [N]", but buffer given by name, see 1249 |{bufname}|. 1250 1251 :bd[elete][!] N1 N2 ... 1252 Do ":bdelete[!]" for buffer N1, N2, etc. The arguments can be 1253 buffer numbers or buffer names (but not buffer names that are 1254 a number). Insert a backslash before a space in a buffer 1255 name. 1256 1257 :N,Mbd[elete][!] 1258 Do ":bdelete[!]" for all buffers in the range N to M 1259 |inclusive|. 1260 1261 :[N]bw[ipeout][!] *:bw* *:bwipe* *:bwipeout* *E517* 1262 :bw[ipeout][!] {bufname} 1263 :N,Mbw[ipeout][!] 1264 :bw[ipeout][!] N1 N2 ... 1265 Like |:bdelete|, but really delete the buffer. Everything 1266 related to the buffer is lost. All marks in this buffer 1267 become invalid, option settings are lost, the jumplist and 1268 tagstack data will be purged, etc. Don't use this 1269 unless you know what you are doing. Examples: > 1270 :.+,$bwipeout " wipe out all buffers after the current 1271 " one 1272 :%bwipeout " wipe out all buffers 1273 < 1274 1275 :[N]bun[load][!] *:bun* *:bunload* *E515* 1276 :bun[load][!] [N] 1277 Unload buffer [N] (default: current buffer). The memory 1278 allocated for this buffer will be freed. The buffer remains 1279 in the buffer list. 1280 If the buffer was changed, this fails, unless when [!] is 1281 specified, in which case the changes are lost. 1282 Any windows for this buffer are closed. If buffer [N] is the 1283 current buffer, another buffer will be displayed instead. 1284 This is the most recent entry in the jump list that points 1285 into a loaded buffer. 1286 1287 :bun[load][!] {bufname} 1288 Like ":bunload[!] [N]", but buffer given by name. 1289 Also see |{bufname}|. 1290 1291 :N,Mbun[load][!] 1292 Do ":bunload[!]" for all buffers in the range N to M 1293 |inclusive|. 1294 1295 :bun[load][!] N1 N2 ... 1296 Do ":bunload[!]" for buffer N1, N2, etc. The arguments can be 1297 buffer numbers or buffer names (but not buffer names that are 1298 a number). Insert a backslash before a space in a buffer 1299 name. 1300 1301 :[N]b[uffer][!] [+cmd] [N] *:b* *:bu* *:buf* *:buffer* *E86* 1302 Edit buffer [N] from the buffer list. If [N] is not given, 1303 the current buffer remains being edited. See |:buffer-!| for 1304 [!]. This will also edit a buffer that is not in the buffer 1305 list, without setting the 'buflisted' flag. 1306 The notation with single quotes does not work here, 1307 `:buf 12'345'` uses 12'345' as a buffer name. 1308 Also see |+cmd|. 1309 1310 :[N]b[uffer][!] [+cmd] {bufname} *{bufname}* 1311 Edit buffer for {bufname} from the buffer list. A partial 1312 name also works, so long as it is unique in the list of 1313 buffers. 1314 Note that a buffer whose name is a number cannot be referenced 1315 by that name; use the buffer number instead. Same is true if 1316 the buffer name starts with a `+`, it will be interpreted as 1317 the start of a |+cmd|. 1318 Insert a backslash before a space in a buffer name. 1319 See |:buffer-!| for [!]. 1320 This will also edit a buffer that is not in the buffer list, 1321 without setting the 'buflisted' flag. 1322 Also see |+cmd|. 1323 1324 :[N]sb[uffer] [+cmd] [N] *:sb* *:sbuffer* 1325 Split window and edit buffer [N] from the buffer list. If [N] 1326 is not given, the current buffer is edited. Respects the 1327 "useopen" setting of 'switchbuf' when splitting. This will 1328 also edit a buffer that is not in the buffer list, without 1329 setting the 'buflisted' flag. 1330 Also see |+cmd|. 1331 1332 :[N]sb[uffer] [+cmd] {bufname} 1333 Split window and edit buffer for |{bufname}| from the buffer 1334 list. This will also edit a buffer that is not in the buffer 1335 list, without setting the 'buflisted' flag. 1336 Note: If what you want to do is split the buffer, make a copy 1337 under another name, you can do it this way: > 1338 :w foobar | sp # 1339 < Also see |+cmd|. 1340 1341 :[N]bn[ext][!] [+cmd] [N] *:bn* *:bnext* *E87* 1342 Go to [N]th next buffer in buffer list. [N] defaults to one. 1343 Wraps around the end of the buffer list. 1344 See |:buffer-!| for [!]. 1345 Also see |+cmd|. 1346 If you are in a help buffer, this takes you to the next help 1347 buffer (if there is one). Similarly, if you are in a normal 1348 (non-help) buffer, this takes you to the next normal buffer. 1349 This is so that if you have invoked help, it doesn't get in 1350 the way when you're browsing code/text buffers. The next 1351 three commands also work like this. 1352 1353 *:sbn* *:sbnext* 1354 :[N]sbn[ext] [+cmd] [N] 1355 Split window and go to [N]th next buffer in buffer list. 1356 Wraps around the end of the buffer list. Uses 'switchbuf' 1357 Also see |+cmd|. 1358 1359 :[N]bN[ext][!] [+cmd] [N] *:bN* *:bNext* *:bp* *:bprevious* *E88* 1360 :[N]bp[revious][!] [+cmd] [N] 1361 Go to [N]th previous buffer in buffer list. [N] defaults to 1362 one. Wraps around the start of the buffer list. 1363 See |:buffer-!| for [!] and 'switchbuf'. 1364 Also see |+cmd|. 1365 1366 :[N]sbN[ext] [+cmd] [N] *:sbN* *:sbNext* *:sbp* *:sbprevious* 1367 :[N]sbp[revious] [+cmd] [N] 1368 Split window and go to [N]th previous buffer in buffer list. 1369 Wraps around the start of the buffer list. 1370 Uses 'switchbuf'. 1371 Also see |+cmd|. 1372 1373 :br[ewind][!] [+cmd] *:br* *:bre* *:brewind* 1374 Go to first buffer in buffer list. If the buffer list is 1375 empty, go to the first unlisted buffer. 1376 See |:buffer-!| for [!]. 1377 1378 :bf[irst] [+cmd] *:bf* *:bfirst* 1379 Same as |:brewind|. 1380 Also see |+cmd|. 1381 1382 :sbr[ewind] [+cmd] *:sbr* *:sbrewind* 1383 Split window and go to first buffer in buffer list. If the 1384 buffer list is empty, go to the first unlisted buffer. 1385 Respects the 'switchbuf' option. 1386 Also see |+cmd|. 1387 1388 :sbf[irst] [+cmd] *:sbf* *:sbfirst* 1389 Same as ":sbrewind". 1390 1391 :bl[ast][!] [+cmd] *:bl* *:blast* 1392 Go to last buffer in buffer list. If the buffer list is 1393 empty, go to the last unlisted buffer. 1394 See |:buffer-!| for [!]. 1395 1396 :sbl[ast] [+cmd] *:sbl* *:sblast* 1397 Split window and go to last buffer in buffer list. If the 1398 buffer list is empty, go to the last unlisted buffer. 1399 Respects 'switchbuf' option. 1400 1401 :[N]bm[odified][!] [+cmd] [N] *:bm* *:bmodified* *E84* 1402 Go to [N]th next modified buffer. Note: this command also 1403 finds unlisted buffers. If there is no modified buffer the 1404 command fails. 1405 1406 :[N]sbm[odified] [+cmd] [N] *:sbm* *:sbmodified* 1407 Split window and go to [N]th next modified buffer. 1408 Respects 'switchbuf' option. 1409 Note: this command also finds buffers not in the buffer list. 1410 1411 :[N]unh[ide] [N] *:unh* *:unhide* *:sun* *:sunhide* 1412 :[N]sun[hide] [N] 1413 Rearrange the screen to open one window for each loaded buffer 1414 in the buffer list. When a count is given, this is the 1415 maximum number of windows to open. 1416 1417 :[N]ba[ll] [N] *:ba* *:ball* *:sba* *:sball* 1418 :[N]sba[ll] [N] Rearrange the screen to open one window for each buffer in 1419 the buffer list. When a count is given, this is the maximum 1420 number of windows to open. 'winheight' also limits the number 1421 of windows opened ('winwidth' if |:vertical| was prepended). 1422 Buf/Win Enter/Leave autocommands are not executed for the new 1423 windows here, that's only done when they are really entered. 1424 When the |:tab| modifier is used new windows are opened in a 1425 new tab, up to 'tabpagemax'. 1426 1427 Note: All the commands above that start editing another buffer, keep the 1428 'readonly' flag as it was. This differs from the ":edit" command, which sets 1429 the 'readonly' flag each time the file is read. 1430 1431 ============================================================================== 1432 12. Special kinds of buffers *special-buffers* 1433 1434 Instead of containing the text of a file, buffers can also be used for other 1435 purposes. A few options can be set to change the behavior of a buffer: 1436 'bufhidden' what happens when the buffer is no longer displayed 1437 in a window. 1438 'buftype' what kind of a buffer this is 1439 'swapfile' whether the buffer will have a swap file 1440 'buflisted' buffer shows up in the buffer list 1441 1442 A few useful kinds of a buffer: 1443 1444 quickfix Used to contain the error list or the location list. See 1445 |:cwindow| and |:lwindow|. This command sets the 'buftype' 1446 option to "quickfix". You are not supposed to change this! 1447 'swapfile' is off. 1448 1449 help Contains a help file. Will only be created with the |:help| 1450 command. The flag that indicates a help buffer is internal 1451 and can't be changed. The 'buflisted' option will be reset 1452 for a help buffer. 1453 1454 terminal A terminal window buffer, see |terminal|. The contents cannot 1455 be read or changed until the job ends. 1456 1457 directory Displays directory contents. Can be used by a file explorer 1458 plugin. The buffer is created with these settings: > 1459 :setlocal buftype=nowrite 1460 :setlocal bufhidden=delete 1461 :setlocal noswapfile 1462 < The buffer name is the name of the directory and is adjusted 1463 when using the |:cd| command. 1464 1465 *scratch-buffer* 1466 scratch Contains text that can be discarded at any time. It is kept 1467 when closing the window, it must be deleted explicitly. 1468 Settings: > 1469 :setlocal buftype=nofile 1470 :setlocal bufhidden=hide 1471 :setlocal noswapfile 1472 < The buffer name can be used to identify the buffer, if you 1473 give it a meaningful name. 1474 1475 *unlisted-buffer* 1476 unlisted The buffer is not in the buffer list. It is not used for 1477 normal editing, but to show a help file, remember a file name 1478 or marks. The ":bdelete" command will also set this option, 1479 thus it doesn't completely delete the buffer. Settings: > 1480 :setlocal nobuflisted 1481 < 1482 1483 vim:tw=78:ts=8:noet:ft=help:norl: