Edit Page
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 21: | Line 21: | ||
<pre> |
<pre> |
||
set showtabline=2 " always show tabs in gvim, but not vim |
set showtabline=2 " always show tabs in gvim, but not vim |
||
+ | |||
" set up tab labels with tab number, buffer name, number of windows |
" set up tab labels with tab number, buffer name, number of windows |
||
function! GuiTabLabel() |
function! GuiTabLabel() |
||
let label = '' |
let label = '' |
||
let bufnrlist = tabpagebuflist(v:lnum) |
let bufnrlist = tabpagebuflist(v:lnum) |
||
+ | |||
" Add '+' if one of the buffers in the tab page is modified |
" Add '+' if one of the buffers in the tab page is modified |
||
for bufnr in bufnrlist |
for bufnr in bufnrlist |
||
Line 32: | Line 34: | ||
endif |
endif |
||
endfor |
endfor |
||
+ | |||
" Append the tab number |
" Append the tab number |
||
let label .= v:lnum.': ' |
let label .= v:lnum.': ' |
||
+ | |||
" Append the buffer name |
" Append the buffer name |
||
let name = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) |
let name = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) |
||
Line 48: | Line 52: | ||
endif |
endif |
||
let label .= name |
let label .= name |
||
+ | |||
" Append the number of windows in the tab page |
" Append the number of windows in the tab page |
||
let wincount = tabpagewinnr(v:lnum, '$') |
let wincount = tabpagewinnr(v:lnum, '$') |
||
return label . ' [' . wincount . ']' |
return label . ' [' . wincount . ']' |
||
endfunction |
endfunction |
||
+ | |||
set guitablabel=%{GuiTabLabel()} |
set guitablabel=%{GuiTabLabel()} |
||
</pre> |
</pre> |
||
Since a tab can contain multiple windows, it can be nice to see at a glance which buffers are loaded in each window in a non-current tab. There is not enough space in a tab label for this, but we can add a tooltip so that we can see what files are loaded by hovering the mouse over the tab label in question. Again, this will only work in GUI Vim. |
Since a tab can contain multiple windows, it can be nice to see at a glance which buffers are loaded in each window in a non-current tab. There is not enough space in a tab label for this, but we can add a tooltip so that we can see what files are loaded by hovering the mouse over the tab label in question. Again, this will only work in GUI Vim. |
||
+ | |||
<pre> |
<pre> |
||
" set up tab tooltips with every buffer name |
" set up tab tooltips with every buffer name |
||
Line 61: | Line 68: | ||
let tip = '' |
let tip = '' |
||
let bufnrlist = tabpagebuflist(v:lnum) |
let bufnrlist = tabpagebuflist(v:lnum) |
||
+ | |||
for bufnr in bufnrlist |
for bufnr in bufnrlist |
||
" separate buffer entries |
" separate buffer entries |
||
Line 66: | Line 74: | ||
let tip .= " \n " |
let tip .= " \n " |
||
endif |
endif |
||
+ | |||
" Add name of buffer |
" Add name of buffer |
||
let name=bufname(bufnr) |
let name=bufname(bufnr) |
||
Line 77: | Line 86: | ||
endif |
endif |
||
let tip.=name |
let tip.=name |
||
+ | |||
" add modified/modifiable flags |
" add modified/modifiable flags |
||
if getbufvar(bufnr, "&modified") |
if getbufvar(bufnr, "&modified") |
||
Line 85: | Line 95: | ||
endif |
endif |
||
endfor |
endfor |
||
+ | |||
return tip |
return tip |
||
endfunction |
endfunction |
||
+ | |||
set guitabtooltip=%{GuiTabToolTip()} |
set guitabtooltip=%{GuiTabToolTip()} |
||
</pre> |
</pre> |
||
Line 159: | Line 171: | ||
set tabline=%!MyTabLine() |
set tabline=%!MyTabLine() |
||
map <C-Tab> :tabnext<CR> |
map <C-Tab> :tabnext<CR> |
||
− | imap |
+ | imap <C-Tab> <C-O>:tabnext<CR> |
map <C-S-Tab> :tabprev<CR> |
map <C-S-Tab> :tabprev<CR> |
||
imap <C-S-Tab> <C-O>:tabprev<CR> |
imap <C-S-Tab> <C-O>:tabprev<CR> |
||
Line 167: | Line 179: | ||
This function is not perfect: the name for a netrw directory appears as [No Name], just like for an unnamed buffer. Feel free to enhance it if you can. — [[User:Tonymec|Tonymec]] 22:49, August 14, 2010 (UTC) |
This function is not perfect: the name for a netrw directory appears as [No Name], just like for an unnamed buffer. Feel free to enhance it if you can. — [[User:Tonymec|Tonymec]] 22:49, August 14, 2010 (UTC) |
||
----- |
----- |
||
− | Here is my tabline function. Unlike the others, it doesn't rely on +gui. It will display 1: (tab #), [n+] (modified count on tab--only if needed) and special help and quickfix buffer labels. This tabline shows all active buffers. To minimize space, dir paths of regular files are shortened to first characters. I based it on the sample tabline in the vim docs. |
+ | Here is my tabline function. Unlike the others, it doesn't rely on +gui. It will display 1: (tab #), [n+] (modified count on tab--only if needed) and special help and quickfix buffer labels. This tabline shows all active buffers. To minimize space, dir paths of regular files are shortened to first characters. I based it on the sample tabline in the vim docs. |
− | Buyer Beware! This is my first attempt at a vim script. If it destroys things, don't say I didn't warn you! Use at your own risk. Finally, any pointers and improvements are welcome. |
+ | Buyer Beware! This is my first attempt at a vim script. If it destroys things, don't say I didn't warn you! Use at your own risk. Finally, any pointers and improvements are welcome. |
To use, just copy and paste the code into your .vimrc. |
To use, just copy and paste the code into your .vimrc. |
||
<pre> |
<pre> |
||
− | set showtabline=2 |
+ | set showtabline=2 " 0, 1 or 2; when to use a tab pages line |
− | set tabline=%!MyTabLine() |
+ | set tabline=%!MyTabLine() " custom tab pages line |
function MyTabLine() |
function MyTabLine() |
||
+ | |||
− | + | let s = '' " complete tabline goes here |
|
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | if getbufvar( b, "&buftype" ) == 'help' |
|
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | let n .= '[Q]' |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | let n .= pathshorten(bufname(b)) |
|
− | + | endif |
|
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | let m += 1 |
|
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | " my default highlighting only underlines the active tab |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
+ | let bc -= 1 |
||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
− | endif |
||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | let s .= '[' . m . '+]' |
|
+ | endif |
||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | " my default highlighting only underlines the active tab |
|
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | endif |
||
+ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | endif |
||
+ | |||
⚫ | |||
+ | |||
endfunction |
endfunction |
||
</pre> |
</pre> |
||
Line 244: | Line 277: | ||
set tabline=%!MyTabLine() |
set tabline=%!MyTabLine() |
||
function MyTabLine() |
function MyTabLine() |
||
+ | |||
− | let s = '' " complete tabline goes here |
+ | let s = '' " complete tabline goes here |
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | for t in range(tabpagenr('$')) |
|
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | if t + 1 == tabpagenr() |
|
+ | let s .= '%#TabLineSel#' |
||
− | endif |
||
− | + | else |
|
− | let s .= ' |
+ | let s .= '%#TabLine#' |
− | + | endif |
|
+ | |||
⚫ | |||
− | + | " empty space |
|
− | + | let s .= ' ' |
|
+ | |||
⚫ | |||
− | + | " set the tab page number (for mouse clicks) |
|
− | let |
+ | let s .= '%' . (t + 1) . 'T' |
+ | |||
⚫ | |||
+ | " set page number string |
||
⚫ | |||
− | + | let s .= t + 1 . ' ' |
|
+ | |||
⚫ | |||
− | + | " get buffer names and statuses |
|
+ | let n = '' "temp string for buffer names while we loop and check buftype |
||
⚫ | |||
− | + | let m = 0 " &modified counter |
|
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
− | else |
||
− | + | for b in tabpagebuflist(t + 1) |
|
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | " others get 1dir/2dir/3dir/fname shortened to 1/2/3/fname |
||
− | " check and ++ tab's &modified count |
||
− | if getbufvar( b, "& |
+ | if getbufvar( b, "&buftype" ) == 'help' |
+ | let n .= '[H]' . fnamemodify( bufname(b), ':t:s/.txt$//' ) |
||
⚫ | |||
⚫ | |||
− | endif |
||
+ | let n .= '[Q]' |
||
⚫ | |||
− | + | else |
|
− | let n .= |
+ | let n .= pathshorten(bufname(b)) |
⚫ | |||
− | endif |
||
− | + | endif |
|
+ | |||
− | endfor |
||
− | + | " check and ++ tab's &modified count |
|
⚫ | |||
⚫ | |||
− | + | let m += 1 |
|
− | + | endif |
|
+ | |||
− | endif |
||
⚫ | |||
− | " add buffer names |
||
− | if |
+ | if bc > 1 |
− | let |
+ | let n .= ' ' |
⚫ | |||
− | else |
||
+ | |||
− | let s .= n |
||
⚫ | |||
− | endif |
||
+ | |||
⚫ | |||
− | + | endfor |
|
+ | |||
⚫ | |||
+ | " add modified label [n+] where n pages in tab are modified |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | let s .= ' |
+ | "let s .= '[' . m . '+]' |
⚫ | |||
⚫ | |||
⚫ | |||
− | if tabpagenr('$') > 1 |
||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
+ | "let s .= '%#TabLineSel#' . ' ' |
||
⚫ | |||
+ | |||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
+ | |||
+ | " right-align the label to close the current tab page |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
+ | |||
endfunction |
endfunction |
||
</pre> |
</pre> |