从Vim7.0开始vim开始正式支持Tab页,可以比较方便地使用标签页了,前面转了一篇文章介绍Tab的使用,今天想实现Alt+N来自动切换标签页的功能,发现1338插件,也就是网上流传的alt+N方案是针对缓冲区的,并不是针对标签页的,实际上非常简单,把下面这些贴到vimrc里面,就OK了。
使用说明:
- Alt+1会切换到1号标签页,同时支持1..10,Alt+0表示10;
- Alt+左右键能够左右移动当前的标签页;
- 下面的代码能够实现给每个标签页数字编号;
VimL语言:
01 " 关于标签页的标题修改 "02 " 使用了自定义函数 GuiTabLabel()03 set showtabline=2 " always show tabs in gvim, but not vim04 set guitablabel=%{GuiTabLabel()
}"05 06 "07 " 修改标签页的标题08 " set up tab labels with tab number, buffer name, number of windows09 "10 function! GuiTabLabel()
"11 let label = ''12 let bufnrlist = tabpagebuflist(
v:lnum)
13 " Add '+' if one of the buffers in the tab page is modified14 for bufnr in bufnrlist15 if getbufvar(
bufnr, "&modified")16 let label = '+'17 break18 endif19 endfor20 " Append the tab number21 let label .= v:lnum.': '22 " Append the buffer name23 let name = bufname(
bufnrlist[tabpagewinnr(
v:lnum)
- 1])
24 if name == ''25 " give a name to no-name documents26 if &buftype=='quickfix'27 let name = '[Quickfix List]'28 else29 let name = '[No Name]'30 endif31 else32 " get only the file name33 let name = fnamemodify(
name,":t")
34 endif35 let label .= name36 " Append the number of windows in the tab page37 let wincount = tabpagewinnr(
v:lnum, '$')
38 return label . ' [' . wincount . ']'39 endfunction"40 41 "42 " 让gvim支持Alt+n来切换标签页43 "44 function! Tabmap_Initialize()
45 for i in range(
1, 9)
46 exe "map ".i."gt"47 endfor48 exe "map 10gt"49 endfunction50 autocmd VimEnter * call BufPos_Initialize()
51 52 "53 " alt+左右键来移动标签54 "55 nn
<silent> <M-left> :if tabpagenr()
== 1\|
exe "tabm ".tabpagenr("$")\|el\|exe "tabm ".(tabpagenr()-2)\|en56 nn
<silent> <M-right> :if tabpagenr()
== tabpagenr(
"$")
\|
tabm 0\|
el\|
exe "tabm ".tabpagenr()\|en
阅读(3761) | 评论(0) | 转发(0) |