robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesdocs: misc #39817c55b6128f8

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