Home Explore Blog CI



neovim

6th chunk of `runtime/doc/tabpage.txt`
136d5eed81d3bd5caec5de83d830cae19c09ab96c07189010000000100000f14
 option.  Additionally, the |tabpagebuflist()|, |tabpagenr()| and
|tabpagewinnr()| functions are useful.

Since the number of tab labels will vary, you need to use an expression for
the whole option.  Something like: >
	:set tabline=%!MyTabLine()

Then define the MyTabLine() function to list all the tab pages labels.  A
convenient method is to split it in two parts:  First go over all the tab
pages and define labels for them.  Then get the label for each tab page. >

	function MyTabLine()
	  let s = ''
	  for i in range(tabpagenr('$'))
	    " select the highlighting
	    if i + 1 == tabpagenr()
	      let s ..= '%#TabLineSel#'
	    else
	      let s ..= '%#TabLine#'
	    endif

	    " set the tab page number (for mouse clicks)
	    let s ..= '%' .. (i + 1) .. 'T'

	    " the label is made by MyTabLabel()
	    let s ..= ' %{MyTabLabel(' .. (i + 1) .. ')} '
	  endfor

	  " after the last tab fill with TabLineFill and reset tab page nr
	  let s ..= '%#TabLineFill#%T'

	  " right-align the label to close the current tab page
	  if tabpagenr('$') > 1
	    let s ..= '%=%#TabLine#%999Xclose'
	  endif

	  return s
	endfunction

Now the MyTabLabel() function is called for each tab page to get its label. >

	function MyTabLabel(n)
	  let buflist = tabpagebuflist(a:n)
	  let winnr = tabpagewinnr(a:n)
	  return bufname(buflist[winnr - 1])
	endfunction

This is just a simplistic example that results in a tab pages line that
resembles the default, but without adding a + for a modified buffer or
truncating the names.  You will want to reduce the width of labels in a
clever way when there is not enough room.  Check the 'columns' option for the
space available.

==============================================================================
5. Setting 'guitablabel'				*setting-guitablabel*

When the GUI tab pages line is displayed, 'guitablabel' can be used to
specify the label to display for each tab page.  Unlike 'tabline', which
specifies the whole tab pages line at once, 'guitablabel' is used for each
label separately.

'guitabtooltip' is very similar and is used for the tooltip of the same label.
This only appears when the mouse pointer hovers over the label, thus it
usually is longer.  Only supported on some systems though.

See the 'statusline' option for the format of the value.

The "%N" item can be used for the current tab page number.  The |v:lnum|
variable is also set to this number when the option is evaluated.
The items that use a file name refer to the current window of the tab page.

Note that syntax highlighting is not used for the option.  The %T and %X
items are also ignored.

A simple example that puts the tab page number and the buffer name in the
label: >
	:set guitablabel=%N\ %f

An example that resembles the default 'guitablabel': Show the number of
windows in the tab page and a '+' if there is a modified buffer: >

	function GuiTabLabel()
	  let label = ''
	  let bufnrlist = tabpagebuflist(v:lnum)

	  " Add '+' if one of the buffers in the tab page is modified
	  for bufnr in bufnrlist
	    if getbufvar(bufnr, "&modified")
	      let label = '+'
	      break
	    endif
	  endfor

	  " Append the number of windows in the tab page if more than one
	  let wincount = tabpagewinnr(v:lnum, '$')
	  if wincount > 1
	    let label ..= wincount
	  endif
	  if label != ''
	    let label ..= ' '
	  endif

	  " Append the buffer name
	  return label .. bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
	endfunction

	set guitablabel=%{GuiTabLabel()}

Note that the function must be defined before setting the option, otherwise
you get an error message for the function not being known.

If you want to fall back to the default label, return an empty string.

If you want to show something specific for a tab page, you might want to use a
tab page local variable. |t:var|


 vim:tw=78:ts=8:noet:ft=help:norl:

Title: Setting 'guitablabel' and Example
Summary
This section discusses the 'guitablabel' option, used to specify the label for each tab page in the GUI tab line, and 'guitabtooltip', used for the tooltip of the same label. It mentions how '%N' can be used for the tab page number and provides an example of combining the tab page number and buffer name. Also gives an example of how to display the number of windows in the tab page and a '+' if there is a modified buffer.