How to list tabs in vim?

Vim is a very productive editor, and I like to use it every day, but I found that moving between tabs takes longer than necessary.

When I want to switch to another tab, I often repeat gt or gt several times. Vim provides the best way to achieve the required tab - n + gt , where n is the tab number. But to use it, you must first calculate the account number. It quickly gets boring if you open a dozen tabs.

I think it would be nice to list the tabs. The singular on each tab in front of the file name is something like this:

 1 Readme | 2 main.c | 3 main.h | 4 process.h 

I hope you can configure vim for this by editing the configuration or using some kind of plugin.

Is there any way to achieve it?

+6
source share
2 answers

You can use the tabline parameter to set the tab label in vim console mode. See the Help at :h setting-tabline , which also shows a very simple minimal example that you can customize as you like, for example. what do you want for, I would use something like this:

 fu! MyTabLabel(n) let buflist = tabpagebuflist(a:n) let winnr = tabpagewinnr(a:n) let string = fnamemodify(bufname(buflist[winnr - 1]), ':t') return empty(string) ? '[unnamed]' : string endfu fu! 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' " display tabnumber (for use with <count>gt, etc) let s .= ' '. (i+1) . ' ' " the label is made by MyTabLabel() let s .= ' %{MyTabLabel(' . (i + 1) . ')} ' if i+1 < tabpagenr('$') let s .= ' |' endif endfor return s endfu set tabline=%!MyTabLine() 
+5
source

If you are using gvim :

 set guitablabel=(%N)\ %t\ %M 

Type :help tabline and :help guitablabel to read more.

The document has a function MyTabLine() .

+2
source

Source: https://habr.com/ru/post/919875/


All Articles