aboutsummaryrefslogtreecommitdiff
path: root/plugin/statusline.vim
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/statusline.vim')
-rw-r--r--plugin/statusline.vim125
1 files changed, 125 insertions, 0 deletions
diff --git a/plugin/statusline.vim b/plugin/statusline.vim
new file mode 100644
index 0000000..98fc4a9
--- /dev/null
+++ b/plugin/statusline.vim
@@ -0,0 +1,125 @@
1augroup MAX_FANCYLINE
2 set noshowmode | " mode will be shown twice, in lightline and below, so we want to deactivate one
3 set laststatus=2 | " required by AirLine and Lightline, without status line does not appear until a window split
4
5 let g:status_sym_start = ''
6 let g:status_sym_end = ''
7 let g:status_sym_sep_start = ''
8 let g:status_sym_sep_end = ''
9 let g:symbol_branch = ''
10
11 if &term == "linux"
12 let g:symbol_branch = ''
13
14 let g:group_active = "StatusLineTerm"
15 let g:group_inactive = "StatusLineTermNC"
16 let g:group_tabline = "StatusLineTerm"
17 else
18 let g:group_active = "StatusLine"
19 let g:group_inactive = "StatusLineNC"
20 let g:group_tabline = "TabLine"
21 endif
22
23 " this function reverts foreground color and background color of a given
24 " highlight group and returns the name of a newly created _invert group
25 function! CreateInvertGroup(highlight_group)
26 if(synIDattr(hlID(a:highlight_group), "reverse")==1)
27 let w:color=synIDattr(hlID(a:highlight_group), "fg#")
28 else
29 let w:color=synIDattr(hlID(a:highlight_group), "bg#")
30 endif
31
32 let l:retval=a:highlight_group.'_invert'
33 if(exists('w:color') && w:color == '')
34 let w:color = 'NONE'
35 endif
36 silent! exec 'highlight '.retval.' gui=NONE guifg='.w:color.' cterm=NONE ctermfg='.w:color
37 return l:retval
38 endfunction
39
40 function! UpdateStatus(highlight_group)
41 let l:invert_group = CreateInvertGroup(a:highlight_group)
42 let l:mode = get({
43 \ 'n' : 'normal',
44 \ 'i' : 'insert',
45 \ 'R' : 'replace',
46 \ 'v' : 'visual',
47 \ "V" : 'visual line',
48 \ "\<C-V>" : 'visual block',
49 \ 'c' : 'command',
50 \ 's' : 'select',
51 \ 'S' : 'select line',
52 \ "\<C-s>" : 'select block',
53 \ 't' : 'terminal'
54 \ }, mode(), mode())
55 return ''
56 \ ."%#StatusLineHighlight#"
57 \ ."%#".a:highlight_group."#"
58 \ ."%(%w%h%q%)".' '.l:mode.' '.g:status_sym_sep_start.' '
59 \ ."%{(argc()>0\ ?\ argidx()+1.':'.argc().' '.g:status_sym_sep_start.' '\ :\ '')}"
60 \ ."%{winbufnr(0).' '.g:status_sym_sep_start}"
61 \ ."%{(&readonly\ ?\ '\ \ 🔒'\ :\ '')}"
62 \ ."%{(&modified\ ?\ '\ \ '.nr2char(0xF0C7).'\ '\ :\ '')\ }"
63 \ ."%{(haslocaldir() ?\ fnamemodify(getcwd(),\ ':.').' '.nr2char(0xe0b1)\ \:\ '')}\ "
64 \ ."%{(&buftype\ ==\ \"terminal\"\ ?\ has('nvim')?b:term_title:expand(&titlestring)\ :\ substitute(expand('%:p'),\ '^'.getcwd(-1).'/*',\ '',\ ''))\ }"
65 \ ."%1(%)"
66 \ ."%#".l:invert_group."#"
67 \ .g:status_sym_end
68 \ .''
69 \ ."%="
70 \ .''
71 \ ."%#".l:invert_group."#"
72 \ .g:status_sym_start
73 \ ."%#".a:highlight_group."#"
74 \ ."%1(%)"
75 \ ."%{(&filetype\ !=\ ''\ ?\ &filetype\ :\ &buftype)}"
76 \ ."%(\ %{g:status_sym_sep_end}\ %)"
77 \ ."%{(&spell\ ?\ &spelllang.' '.g:status_sym_sep_end\ :\ '')}"
78 \ ."%{(&fileencoding\ !=\ ''\ ?\ &fileencoding.' '.g:status_sym_sep_end.' '\ :\ '')}"
79 \ ."%{(&fileformat\ !=\ ''\ ?\ ' '.&fileformat.' '\ :\ '')}"
80 \ .g:status_sym_sep_end.' '
81 \ ."%4l:%-3c"
82 \ .g:status_sym_sep_end.' '
83 \ ."%-3p%%"
84 endfunction
85
86 function! UpdateTabline(highlight_group)
87 let l:invert_group = CreateInvertGroup(a:highlight_group)
88 return ''
89 \ ."%#".a:highlight_group."#"
90 \ ."%3( \ %)\ "
91 \ ."%{getcwd(-1)}\ "
92 \ .g:status_sym_sep_start.' '
93 \ ."%(\ ".g:symbol_branch."\ %{fugitive#head()}\ %)"
94 \ ."%#".l:invert_group."#"
95 \ .g:status_sym_end
96 \ .''
97 \ ."%="
98 \ .''
99 \ ."%#".l:invert_group."#"
100 \ .g:status_sym_start
101 \ ."%#".a:highlight_group."#"
102 \ ."%3(\ %)"
103 \ ."%(%{v:servername}\ %{v:this_session}%)"
104 \ .g:status_sym_sep_end.' '
105 \ ."%(\ \ %{tabpagenr()}/%{tabpagenr('$')}\ %)"
106 \ ."%##"
107 \ ."" " end
108 endfunction
109
110 function! ApplyColorScheme()
111 " set termguicolors | " When on, uses highlight-guifg and highlight-guibg attributes in the terminal (=24bit color) incompatible with nvim
112 " set t_ut=
113 " set up statusline, global and current window individually
114 set statusline=%!UpdateStatus(g:group_inactive)
115 setlocal statusline=%!UpdateStatus(g:group_active)
116 " set up the tabline (match colors)
117 set tabline=%!UpdateTabline(g:group_tabline)
118 endfunction
119 " apply colors from the loaded colorscheme...
120 " when changing the colorscheme also apply new colors to the statusbar...
121 autocmd VimEnter,ColorScheme * call ApplyColorScheme()
122
123 autocmd WinEnter * setlocal statusline=%!UpdateStatus(g:group_active)
124 autocmd WinLeave * setlocal statusline<
125augroup END " MAX_FANCYLINE
..