summaryrefslogtreecommitdiffstats
path: root/vimrcs/statusline.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vimrcs/statusline.vim')
-rw-r--r--vimrcs/statusline.vim70
1 files changed, 70 insertions, 0 deletions
diff --git a/vimrcs/statusline.vim b/vimrcs/statusline.vim
new file mode 100644
index 0000000..6bf42ed
--- /dev/null
+++ b/vimrcs/statusline.vim
@@ -0,0 +1,70 @@
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
33" 文件名标签
34function MyShortTabLabel(n)
35 let buflist = tabpagebuflist(a:n)
36 let label = bufname (buflist[tabpagewinnr (a:n) -1])
37 let filename = fnamemodify (label, ':t')
38 return filename
39endfunction
40" 完整路径标签
41function MyTabLabel(n)
42 let buflist = tabpagebuflist(a:n)
43 let winnr = tabpagewinnr(a:n)
44 return bufname(buflist[winnr - 1])
45endfunction
46
47" 状态栏显示git分支
48function! GitBranch()
49 " 获取当前所在分支名,注意不要保留开头的*和行末的空符号
50 let s:branch = system("git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/\\1/' | tr -d '\n' | tr -d ' '")
51 return strlen(s:branch) ? 'b: '.s:branch.'> ' : ''
52endfunction
53
54set laststatus=2 " 显示状态栏(默认值为 1,无法显示状态栏)
55set statusline=%f%m%r%h%w\ >\ %{GitBranch()}%=\ <\ %{&ff},\ %{&fenc}\ <\ %y\ <\ %l,%v\ <\ %p%%\ <\ lines=%L
56
57function! CurDir()
58 let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
59 return curdir
60endfunction
61
62" 标签样式
63" TabLineFill tab pages line, where there are no labels
64hi TabLineFill term=none
65hi TabLineFill ctermfg=DarkGrey
66hi TabLineFill guifg=#777777
67" TabLineSel tab pages line, active tab page label
68hi TabLineSel term=inverse
69hi TabLineSel cterm=none ctermfg=yellow ctermbg=Black
70hi TabLineSel gui=none guifg=yellow guibg=Black