aboutsummaryrefslogtreecommitdiffstats
path: root/vim/vimrcs/statusline.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/vimrcs/statusline.vim')
-rw-r--r--vim/vimrcs/statusline.vim69
1 files changed, 69 insertions, 0 deletions
diff --git a/vim/vimrcs/statusline.vim b/vim/vimrcs/statusline.vim
new file mode 100644
index 0000000..7bdee34
--- /dev/null
+++ b/vim/vimrcs/statusline.vim
@@ -0,0 +1,69 @@
1set guitablabel=%{ShortTabLabel()}
2function ShortTabLabel ()
3 let bufnrlist = tabpagebuflist (v:lnum)
4 let label = bufname (bufnrlist[tabpagewinnr (v:lnum) -1])
5 let filename = fnamemodify (label, ':t')
6 return filename
7endfunction
8
9set tabline=%!MyTabLine()
10function MyTabLine()
11 let s = ''
12 for i in range(tabpagenr('$'))
13 " 选择高亮
14 if i + 1 == tabpagenr()
15 let s .= '%#TabLineSel#'
16 else
17 let s .= '%#TabLine#'
18 endif
19 " 设置标签页号 (用于鼠标点击)
20 let s .= '%' . (i + 1) . 'T'
21 " MyTabLabel() 提供完整路径标签 MyShortTabLabel 提供文件名标签
22 let s .= ' %{MyShortTabLabel(' . (i + 1) . ')} '
23 endfor
24 " 最后一个标签页之后用 TabLineFill 填充并复位标签页号
25 let s .= '%#TabLineFill#%T'
26 " 右对齐用于关闭当前标签页的标签
27 if tabpagenr('$') > 1
28 let s .= '%=%#TabLine#%999Xclose'
29 endif
30 return s
31endfunction
32" 文件名标签
33function MyShortTabLabel(n)
34 let buflist = tabpagebuflist(a:n)
35 let label = bufname (buflist[tabpagewinnr (a:n) -1])
36 let filename = fnamemodify (label, ':t')
37 return filename
38endfunction
39"完整路径标签
40function MyTabLabel(n)
41 let buflist = tabpagebuflist(a:n)
42 let winnr = tabpagewinnr(a:n)
43 return bufname(buflist[winnr - 1])
44endfunction
45
46" 状态栏显示git分支函数
47function! GitBranch()
48 " 获取当前所在分支名,注意不要保留开头的*和行末的空符号
49 let s:branch = system("git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/\\1/' | tr -d '\n' | tr -d ' '")
50 return strlen(s:branch) ? 'b: '.s:branch.'> ' : ''
51endfunction
52
53set laststatus=2 "显示状态栏(默认值为 1,无法显示状态栏)
54set statusline=%f%m%r%h%w\ >\ %{GitBranch()}%=\ <\ %{&ff},\ %{&fenc}\ <\ %y\ <\ %l,%v\ <\ %p%%\ <\ lines=%L
55
56function! CurDir()
57 let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
58 return curdir
59endfunction
60
61"标签样式
62" TabLineFill tab pages line, where there are no labels
63hi TabLineFill term=none
64hi TabLineFill ctermfg=DarkGrey
65hi TabLineFill guifg=#777777
66" TabLineSel tab pages line, active tab page label
67hi TabLineSel term=inverse
68hi TabLineSel cterm=none ctermfg=yellow ctermbg=Black
69hi TabLineSel gui=none guifg=yellow guibg=Black