tabpage.txt (17738B)
1 *tabpage.txt* Nvim 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7 Editing with windows in multiple tab pages. *tab-page* *tabpage* 8 9 The commands which have been added to use multiple tab pages are explained 10 here. Additionally, there are explanations for commands that work differently 11 when used in combination with more than one tab page. 12 13 Type |gO| to see the table of contents. 14 15 ============================================================================== 16 1. Introduction *tab-page-intro* 17 18 A tab page holds one or more windows. You can easily switch between tab 19 pages, so that you have several collections of windows to work on different 20 things. 21 22 Usually you will see a list of labels at the top of the Vim window, one for 23 each tab page. With the mouse you can click on the label to jump to that tab 24 page. There are other ways to move between tab pages, see below. 25 26 Most commands work only in the current tab page. That includes the |CTRL-W| 27 commands, |:windo|, |:all| and |:ball| (when not using the |:tab| modifier). 28 The commands that are aware of other tab pages than the current one are 29 mentioned below. 30 31 Tab pages are also a nice way to edit a buffer temporarily without changing 32 the current window layout. Open a new tab page, do whatever you want to do 33 and close the tab page. 34 35 *tab-ID* *tabid* *tabpageid* 36 Each tab page has a unique identifier called the tab ID. This identifier will 37 not change within a Vim session -- even when rearranging tabs. 38 |nvim_get_current_tabpage()| returns the tab ID and |nvim_list_tabpages()| 39 lists tab IDs in the order they're displayed. Additionally, the tabs are 40 numbered from left to right starting at 1: this is the tab number returned by 41 |tabpagenr()|. However, the tab number may change when tabs are opened, 42 closed, or rearranged. |nvim_tabpage_get_number()| converts a tab ID to a tab 43 number. 44 45 46 ============================================================================== 47 2. Commands *tab-page-commands* 48 49 OPENING A NEW TAB PAGE: 50 51 When starting Vim "vim -p filename ..." opens each file argument in a separate 52 tab page (up to 'tabpagemax'). See |-p| 53 54 A double click with the mouse in the non-GUI tab pages line opens a new, empty 55 tab page. It is placed left of the position of the click. The first click 56 may select another tab page first, causing an extra screen update. 57 58 This also works in a few GUI versions, esp. Win32. But only when clicking 59 right of the labels. 60 61 In the GUI tab pages line you can use the right mouse button to open menu. 62 |tabline-menu|. 63 64 For the related autocommands see |tabnew-autocmd|. 65 66 :[count]tabe[dit] *:tabe* *:tabedit* *:tabnew* 67 :[count]tabnew 68 Open a new tab page with an empty window, after the current 69 tab page. If [count] is given the new tab page appears after 70 the tabpage [count] otherwise the new tab page will appear 71 after the current one. > 72 :tabnew " opens tabpage after the current one 73 :.tabnew " as above 74 :+tabnew " opens tabpage after the next tab page 75 " note: it is one further than :tabnew 76 :-tabnew " opens tabpage before the current 77 :0tabnew " opens tabpage before the first one 78 :$tabnew " opens tabpage after the last one 79 80 :[count]tabe[dit] [++opt] [+cmd] {file} 81 :[count]tabnew [++opt] [+cmd] {file} 82 Open a new tab page and edit {file}, like with |:edit|. 83 For [count] see |:tabnew| above. 84 85 :[count]tabf[ind] [++opt] [+cmd] {file} *:tabf* *:tabfind* 86 Open a new tab page and edit {file} in 'path', like with 87 |:find|. For [count] see |:tabnew| above. 88 89 :[count]tab {cmd} *:tab* 90 Execute {cmd} and when it opens a new window open a new tab 91 page instead. Doesn't work for |:diffsplit|, |:diffpatch|, 92 |:execute| and |:normal|. 93 If [count] is given the new tab page appears after the tab 94 page [count] otherwise the new tab page will appear after the 95 current one. 96 Examples: > 97 :tab split " opens current buffer in new tab page 98 :tab help gt " opens tab page with help for "gt" 99 :.tab help gt " as above 100 :+tab help " opens tab page with help after the next 101 " tab page 102 :-tab help " opens tab page with help before the 103 " current one 104 :0tab help " opens tab page with help before the 105 " first one 106 :$tab help " opens tab page with help after the last 107 " one 108 109 CTRL-W gf Open a new tab page and edit the file name under the cursor. 110 See |CTRL-W_gf|. 111 112 CTRL-W gF Open a new tab page and edit the file name under the cursor 113 and jump to the line number following the file name. 114 See |CTRL-W_gF|. 115 116 CLOSING A TAB PAGE: 117 118 Closing the last window of a tab page closes the tab page too, unless there is 119 only one tab page. 120 121 Using the mouse: If the tab page line is displayed you can click in the "X" at 122 the top right to close the current tab page. A custom 'tabline' may show 123 something else. 124 125 *:tabc* *:tabclose* 126 :tabc[lose][!] Close current tab page. 127 This command fails when: 128 - There is only one tab page on the screen. *E784* 129 - When 'hidden' is not set, [!] is not used, a buffer has 130 changes, and there is no other window on this buffer. 131 Changes to the buffer are not written and won't get lost, so 132 this is a "safe" command. > 133 :tabclose " close the current tab page 134 135 :{count}tabc[lose][!] 136 :tabc[lose][!] {count} 137 Close tab page {count}. Fails in the same way as `:tabclose` 138 above. > 139 :-tabclose " close the previous tab page 140 :+tabclose " close the next tab page 141 :1tabclose " close the first tab page 142 :$tabclose " close the last tab page 143 :tabclose -2 " close the 2nd previous tab page 144 :tabclose + " close the next tab page 145 :tabclose 3 " close the third tab page 146 :tabclose $ " close the last tab page 147 :tabclose # " close the last accessed tab page 148 149 When a tab page is closed the next tab page will become the current one. This 150 behaviour can be customized using the 'tabclose' option. 151 152 *:tabo* *:tabonly* 153 :tabo[nly][!] Close all other tab pages. 154 When the 'hidden' option is set, all buffers in closed windows 155 become hidden. 156 When 'hidden' is not set, and the 'autowrite' option is set, 157 modified buffers are written. Otherwise, windows that have 158 buffers that are modified are not removed, unless the [!] is 159 given, then they become hidden. But modified buffers are 160 never abandoned, so changes cannot get lost. > 161 :tabonly " close all tab pages except the current one 162 163 :tabo[nly][!] {count} 164 Close all tab pages except {count} one. > 165 :.tabonly " as above 166 :-tabonly " close all tab pages except the previous 167 " one 168 :+tabonly " close all tab pages except the next one 169 :1tabonly " close all tab pages except the first one 170 :$tabonly " close all tab pages except the last one 171 :tabonly - " close all tab pages except the previous 172 " one 173 :tabonly +2 " close all tab pages except the two next 174 " one 175 :tabonly 1 " close all tab pages except the first one 176 :tabonly $ " close all tab pages except the last one 177 :tabonly # " close all tab pages except the last 178 " accessed one 179 180 181 SWITCHING TO ANOTHER TAB PAGE: 182 183 Using the mouse: If the tab page line is displayed you can click in a tab page 184 label to switch to that tab page. Click where there is no label to go to the 185 next tab page. 'tabline' 186 187 :tabn[ext] *:tabn* *:tabnext* *gt* 188 <C-PageDown> *CTRL-<PageDown>* *<C-PageDown>* 189 gt *i_CTRL-<PageDown>* *i_<C-PageDown>* 190 Go to the next tab page. Wraps around from the last to the 191 first one. 192 193 :{count}tabn[ext] 194 :tabn[ext] {count} 195 Go to tab page {count}. The first tab page has number one. > 196 :-tabnext " go to the previous tab page 197 :+tabnext " go to the next tab page 198 :+2tabnext " go to the two next tab page 199 :1tabnext " go to the first tab page 200 :$tabnext " go to the last tab page 201 :tabnext $ " as above 202 :tabnext # " go to the last accessed tab page 203 :tabnext - " go to the previous tab page 204 :tabnext -1 " as above 205 :tabnext + " go to the next tab page 206 :tabnext +1 " as above 207 208 {count}<C-PageDown> 209 {count}gt Go to tab page {count}. The first tab page has number one. 210 211 :tabp[revious] *:tabp* *:tabprevious* *gT* *:tabN* 212 :tabN[ext] *:tabNext* *CTRL-<PageUp>* 213 <C-PageUp> *<C-PageUp>* *i_CTRL-<PageUp>* *i_<C-PageUp>* 214 gT Go to the previous tab page. Wraps around from the first one 215 to the last one. 216 217 :tabp[revious] {count} 218 :tabN[ext] {count} 219 {count}<C-PageUp> 220 {count}gT Go {count} tab pages back. Wraps around from the first one 221 to the last one. Note that the use of {count} is different 222 from |:tabnext|, where it is used as the tab page number. 223 224 :tabr[ewind] *:tabfir* *:tabfirst* *:tabr* *:tabrewind* 225 :tabfir[st] Go to the first tab page. 226 227 *:tabl* *:tablast* 228 :tabl[ast] Go to the last tab page. 229 230 <C-Tab> *CTRL-<Tab>* *<C-Tab>* 231 g<Tab> *g<Tab>* *CTRL-W_g<Tab>* 232 CTRL-W g<Tab> Go to the last accessed tab page. 233 234 Other commands: 235 *:tabs* 236 :tabs List the tab pages and the windows they contain. 237 Shows a ">" for the current window. 238 Shows a "+" for modified buffers. 239 For example: 240 Tab page 1 ~ 241 + tabpage.txt ~ 242 ex_docmd.c ~ 243 Tab page 2 ~ 244 > main.c ~ 245 246 247 REORDERING TAB PAGES: 248 249 :tabm[ove] [N] *:tabm* *:tabmove* 250 :[N]tabm[ove] 251 Move the current tab page to after tab page N. Use zero to 252 make the current tab page the first one. N is counted before 253 the move, thus if the second tab page is the current one, 254 `:tabmove 1` and `:tabmove 2` have no effect. 255 Without N the tab page is made the last one. > 256 :.tabmove " do nothing 257 :-tabmove " move the tab page to the left 258 :+tabmove " move the tab page to the right 259 :0tabmove " move the tab page to the first 260 :tabmove 0 " as above 261 :tabmove " move the tab page to the last 262 :$tabmove " as above 263 :tabmove $ " as above 264 :tabmove # " move the tab page after the last accessed 265 " tab page 266 267 :tabm[ove] +[N] 268 :tabm[ove] -[N] 269 Move the current tab page N places to the right (with +) or to 270 the left (with -). > 271 :tabmove - " move the tab page to the left 272 :tabmove -1 " as above 273 :tabmove + " move the tab page to the right 274 :tabmove +1 " as above 275 276 277 Note that although it is possible to move a tab page behind the N-th one by 278 using :Ntabmove. And move it by N places by using :+Ntabmove. For 279 clarification what +N means in this context see |[range]|. 280 281 282 LOOPING OVER TAB PAGES: 283 284 *:tabd* *:tabdo* 285 :[range]tabd[o] {cmd} 286 Execute {cmd} in each tab page or, if [range] is given, only 287 in tabpages which tab page number is in the [range]. It works 288 like doing this: > 289 :tabfirst 290 :{cmd} 291 :tabnext 292 :{cmd} 293 etc. 294 < This only operates in the current window of each tab page. 295 When an error is detected on one tab page, further tab pages 296 will not be visited. 297 The last tab page (or where an error occurred) becomes the 298 current tab page. 299 {cmd} can contain '|' to concatenate several commands. 300 {cmd} must not open or close tab pages or reorder them. 301 Also see |:windo|, |:argdo|, |:bufdo|, |:cdo|, |:ldo|, |:cfdo| 302 and |:lfdo|. 303 304 ============================================================================== 305 3. Other items *tab-page-other* 306 307 *tabline-menu* 308 The GUI tab pages line has a popup menu. It is accessed with a right click. 309 The entries are: 310 Close Close the tab page under the mouse pointer. The 311 current one if there is no label under the mouse 312 pointer. 313 New Tab Open a tab page, editing an empty buffer. It appears 314 to the left of the mouse pointer. 315 Open Tab... Like "New Tab" and additionally use a file selector to 316 select a file to edit. 317 318 Diff mode works per tab page. You can see the diffs between several files 319 within one tab page. Other tab pages can show differences between other 320 files. 321 322 Variables local to a tab page start with "t:". |tabpage-variable| 323 324 Currently there is only one option local to a tab page: 'cmdheight'. 325 326 *tabnew-autocmd* 327 The TabLeave and TabEnter autocommand events can be used to do something when 328 switching from one tab page to another. The exact order depends on what you 329 are doing. When creating a new tab page this works as if you create a new 330 window on the same buffer and then edit another buffer. Thus ":tabnew" 331 triggers: 332 WinLeave leave current window 333 TabLeave leave current tab page 334 WinEnter enter window in new tab page 335 TabEnter enter new tab page 336 BufLeave leave current buffer 337 BufEnter enter new empty buffer 338 339 When switching to another tab page the order is: 340 BufLeave 341 WinLeave 342 TabLeave 343 WinEnter 344 TabEnter 345 BufEnter 346 347 When entering a new tab page (|:tabnew|), TabNew is triggered before TabEnter 348 and after WinEnter. 349 350 ============================================================================== 351 4. Setting 'tabline' *setting-tabline* 352 353 The 'tabline' option specifies what the line with tab pages labels looks like. 354 It is only used when there is no GUI tab line. 355 356 You can use the 'showtabline' option to specify when you want the line with 357 tab page labels to appear: never, when there is more than one tab page or 358 always. 359 360 The highlighting of the tab pages line is set with the groups TabLine 361 TabLineSel and TabLineFill. |hl-TabLine| |hl-TabLineSel| |hl-TabLineFill| 362 363 A "+" will be shown for a tab page that has a modified window. The number of 364 windows in a tabpage is also shown. Thus "3+" means three windows and one of 365 them has a modified buffer. 366 367 The 'tabline' option allows you to define your preferred way to tab pages 368 labels. This isn't easy, thus an example will be given here. 369 370 For basics see the 'statusline' option. The same items can be used in the 371 'tabline' option. Additionally, the |tabpagebuflist()|, |tabpagenr()| and 372 |tabpagewinnr()| functions are useful. 373 374 Since the number of tab labels will vary, you need to use an expression for 375 the whole option. Something like: > 376 :set tabline=%!MyTabLine() 377 378 Then define the MyTabLine() function to list all the tab pages labels. A 379 convenient method is to split it in two parts: First go over all the tab 380 pages and define labels for them. Then get the label for each tab page. > 381 382 function MyTabLine() 383 let s = '' 384 for i in range(tabpagenr('$')) 385 " select the highlighting 386 if i + 1 == tabpagenr() 387 let s ..= '%#TabLineSel#' 388 else 389 let s ..= '%#TabLine#' 390 endif 391 392 " set the tab page number (for mouse clicks) 393 let s ..= '%' .. (i + 1) .. 'T' 394 395 " the label is made by MyTabLabel() 396 let s ..= ' %{MyTabLabel(' .. (i + 1) .. ')} ' 397 endfor 398 399 " after the last tab page fill with TabLineFill and reset tab page nr 400 let s ..= '%#TabLineFill#%T' 401 402 " right-align the label to close the current tab page 403 if tabpagenr('$') > 1 404 let s ..= '%=%#TabLine#%999Xclose' 405 endif 406 407 return s 408 endfunction 409 410 Now the MyTabLabel() function is called for each tab page to get its label. > 411 412 function MyTabLabel(n) 413 let buflist = tabpagebuflist(a:n) 414 let winnr = tabpagewinnr(a:n) 415 return bufname(buflist[winnr - 1]) 416 endfunction 417 418 This is just a simplistic example that results in a tab pages line that 419 resembles the default, but without adding a + for a modified buffer or 420 truncating the names. You will want to reduce the width of labels in a 421 clever way when there is not enough room. Check the 'columns' option for the 422 space available. 423 424 ============================================================================== 425 5. Setting 'guitablabel' *setting-guitablabel* 426 427 When the GUI tab pages line is displayed, 'guitablabel' can be used to 428 specify the label to display for each tab page. Unlike 'tabline', which 429 specifies the whole tab pages line at once, 'guitablabel' is used for each 430 label separately. 431 432 'guitabtooltip' is very similar and is used for the tooltip of the same label. 433 This only appears when the mouse pointer hovers over the label, thus it 434 usually is longer. Only supported on some systems though. 435 436 See the 'statusline' option for the format of the value. 437 438 The "%N" item can be used for the current tab page number. The |v:lnum| 439 variable is also set to this number when the option is evaluated. 440 The items that use a file name refer to the current window of the tab page. 441 442 Note that syntax highlighting is not used for the option. The %T and %X 443 items are also ignored. 444 445 A simple example that puts the tab page number and the buffer name in the 446 label: > 447 :set guitablabel=%N\ %f 448 449 An example that resembles the default 'guitablabel': Show the number of 450 windows in the tab page and a '+' if there is a modified buffer: > 451 452 function GuiTabLabel() 453 let label = '' 454 let bufnrlist = tabpagebuflist(v:lnum) 455 456 " Add '+' if one of the buffers in the tab page is modified 457 for bufnr in bufnrlist 458 if getbufvar(bufnr, "&modified") 459 let label = '+' 460 break 461 endif 462 endfor 463 464 " Append the number of windows in the tab page if more than one 465 let wincount = tabpagewinnr(v:lnum, '$') 466 if wincount > 1 467 let label ..= wincount 468 endif 469 if label != '' 470 let label ..= ' ' 471 endif 472 473 " Append the buffer name 474 return label .. bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) 475 endfunction 476 477 set guitablabel=%{GuiTabLabel()} 478 479 Note that the function must be defined before setting the option, otherwise 480 you get an error message for the function not being known. 481 482 If you want to fall back to the default label, return an empty string. 483 484 If you want to show something specific for a tab page, you might want to use a 485 tab page local variable. |t:var| 486 487 488 vim:tw=78:ts=8:noet:ft=help:norl: