tabpage.txt 17 KB

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