diff options
author | Teddy Wing | 2014-06-30 23:30:09 -0400 |
---|---|---|
committer | Teddy Wing | 2014-06-30 23:33:48 -0400 |
commit | 9a48292c5dffb741115b0241c18962bae817e2c7 (patch) | |
tree | 036cb6a53249758be192a1d4f4118bcbbc8b2f48 /plugin | |
parent | 731619c3eaa2162e0a6b8113355317e5115b89b6 (diff) | |
download | dotvim-9a48292c5dffb741115b0241c18962bae817e2c7.tar.bz2 |
Create custom tabline.vim plugin
Add a plugin for a custom tabline. Still a lot of room for improvement
here, but I really wanted something that would tell me the tab numbers
to make it easier for me to switch between tabs using #gt.
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/tabline.vim | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/plugin/tabline.vim b/plugin/tabline.vim new file mode 100644 index 0000000..c5781e8 --- /dev/null +++ b/plugin/tabline.vim @@ -0,0 +1,69 @@ +" CustomTabLine +" +" A custom tabline that displays tab numbers for easier navigation between tabs. +" +" CHANGELOG: +" 2014.06.30: +" * Initial version. Very basic. Based on the sample tabline +" implementation in vim help. Shows the tab number, filename without +" path, modification flag, and separator. +" +" TODO: +" 2014.06.30: +" - Truncate filenames when the number of characters in the tabline exceeds the +" width of the window. +" - Improve separator such that it appears between tabs instead of latched onto +" the preceeding tab. +" + +function! CustomTabLine() + 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 CustomTabLabel() + let s .= ' %{CustomTabLabel(' . (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#%999XX' + endif + + return s +endfunction + +function! CustomTabLabel(n) + let buflist = tabpagebuflist(a:n) + let winnr = tabpagewinnr(a:n) + let label = '' + let tab_number = a:n . ': ' + let filename = fnamemodify(bufname(buflist[winnr - 1]), ':p:t') + + if filename == '' + let filename = '[No Name]' + endif + + let label .= tab_number . filename . ' ' + + if getbufvar(buflist[winnr - 1], "&mod") + let label .= '[+] ' + endif + + let label .= '|' + + return label +endfunction + +set tabline=%!CustomTabLine() |