diff options
Diffstat (limited to 'vimrcs/statusline.vim')
-rw-r--r-- | vimrcs/statusline.vim | 70 |
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 @@ | |||
1 | set guitablabel=%{ShortTabLabel()} | ||
2 | function 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 | ||
7 | endfunction | ||
8 | |||
9 | set tabline=%!MyTabLine() | ||
10 | function 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 | ||
31 | endfunction | ||
32 | |||
33 | " 文件名标签 | ||
34 | function 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 | ||
39 | endfunction | ||
40 | " 完整路径标签 | ||
41 | function MyTabLabel(n) | ||
42 | let buflist = tabpagebuflist(a:n) | ||
43 | let winnr = tabpagewinnr(a:n) | ||
44 | return bufname(buflist[winnr - 1]) | ||
45 | endfunction | ||
46 | |||
47 | " 状态栏显示git分支 | ||
48 | function! 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.'> ' : '' | ||
52 | endfunction | ||
53 | |||
54 | set laststatus=2 " 显示状态栏(默认值为 1,无法显示状态栏) | ||
55 | set statusline=%f%m%r%h%w\ >\ %{GitBranch()}%=\ <\ %{&ff},\ %{&fenc}\ <\ %y\ <\ %l,%v\ <\ %p%%\ <\ lines=%L | ||
56 | |||
57 | function! CurDir() | ||
58 | let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g") | ||
59 | return curdir | ||
60 | endfunction | ||
61 | |||
62 | " 标签样式 | ||
63 | " TabLineFill tab pages line, where there are no labels | ||
64 | hi TabLineFill term=none | ||
65 | hi TabLineFill ctermfg=DarkGrey | ||
66 | hi TabLineFill guifg=#777777 | ||
67 | " TabLineSel tab pages line, active tab page label | ||
68 | hi TabLineSel term=inverse | ||
69 | hi TabLineSel cterm=none ctermfg=yellow ctermbg=Black | ||
70 | hi TabLineSel gui=none guifg=yellow guibg=Black | ||