aboutsummaryrefslogtreecommitdiff
path: root/plugin/vim-fancy-line.vim
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/vim-fancy-line.vim')
-rwxr-xr-xplugin/vim-fancy-line.vim176
1 files changed, 176 insertions, 0 deletions
diff --git a/plugin/vim-fancy-line.vim b/plugin/vim-fancy-line.vim
new file mode 100755
index 0000000..8e470ff
--- /dev/null
+++ b/plugin/vim-fancy-line.vim
@@ -0,0 +1,176 @@
1scriptencoding utf-8
2
3augroup MAX_FANCYLINE
4 set noshowmode | " mode would otherwise be shown twice- in lightline and below. We want to deactivate one.
5 set laststatus=2 | " required by AirLine and Lightline, without status line does not appear until a window split
6
7
8 if (&term ==? 'linux' && &termguicolors == 0)
9 let g:group_active = 'StatusLineTerm'
10 let g:group_inactive = 'StatusLineTermNC'
11 let g:group_tabline = 'TabLine'
12 let g:status_sym_start = ''
13 let g:status_sym_end = '▶'
14 let g:status_sym_sep_start = '│'
15 let g:status_sym_sep_end = '│'
16 let g:symbol_branch = ''
17 let g:symbol_screen_edge = '░'
18 else
19 let g:group_active = 'StatusLine'
20 let g:group_inactive = 'StatusLineNC'
21 let g:group_tabline = 'TabLine'
22 let g:status_sym_start = ''
23 let g:status_sym_end = ''
24 let g:status_sym_sep_start = '│'
25 let g:status_sym_sep_end = '│'
26 let g:symbol_branch = ''
27 let g:symbol_screen_edge = '░'
28 endif
29
30
31 " this function reverts foreground color and background color of a given
32 " highlight group and returns the name of a newly created _invert group
33 function! CreateInvertGroup(highlight_group)
34
35 if(synIDattr(synIDtrans(hlID(a:highlight_group)), 'reverse')==0)
36 let w:color=synIDattr(hlID(a:highlight_group), 'bg#')
37 let w:termcolor=synIDattr(hlID(a:highlight_group), 'bg')
38 else
39 let w:color=synIDattr(hlID(a:highlight_group), 'fg#')
40 let w:termcolor=synIDattr(hlID(a:highlight_group), 'fg')
41 endif
42
43 let l:retval=a:highlight_group.'_invert'
44 if(exists('w:color') && w:color ==# '')
45 let w:color = 'NONE'
46 endif
47 if(exists('w:termcolor') && w:termcolor ==# '')
48 let w:termcolor = 'NONE'
49 endif
50
51 silent! exec 'highlight! '.l:retval.' guifg='.w:color
52 silent! exec 'highlight! '.l:retval.' ctermfg='.w:termcolor
53
54 return l:retval
55 endfunction
56
57 function! UpdateStatus(highlight_group)
58 let l:invert_group = CreateInvertGroup(a:highlight_group)
59 let l:mode = get({
60 \ 'n' : 'normal',
61 \ 'i' : 'insert',
62 \ 'R' : 'replace',
63 \ 'v' : 'visual',
64 \ 'V' : 'visual line',
65 \ "\<C-V>" : 'visual block',
66 \ 'c' : 'command',
67 \ 's' : 'select',
68 \ 'S' : 'select line',
69 \ "\<C-s>" : 'select block',
70 \ 't' : 'terminal'
71 \ }, mode(), mode())
72 return ''
73 \ .'%#StatusLineHighlight#'
74 \ .'%#'.a:highlight_group.'#'
75 \ .g:symbol_screen_edge
76 \ .'%{&buftype != "" ? " ".&buftype : ""}'
77 \ .' '.l:mode.g:status_sym_sep_start
78 \ .'%{argc() > 1 ? " ".(argidx() + 1).":".argc()." ".g:status_sym_sep_start : ""}'
79 \ .'%{haslocaldir() ? fnamemodify(getcwd(), ":.:~")." " :""}'
80 \ .'%{&readonly ? " 🔒" : ""}'
81 \ .'%{&modified ? " 💾 " : ""}'
82 \ .'%{" [".winbufnr(0)."] "}'
83 \ .'%{bufname("%") == "" ? "" : fnamemodify(expand("%"), ":~:.")}'
84 \ .'%{&titlestring ? has("nvim") ? b:term_title:expand(&titlestring) : "" }'
85 \ .'%{exists("w:quickfix_title") ? w:quickfix_title : ""}'
86 \ .' '
87 \ .'%#'.l:invert_group.'#'
88 \ .g:status_sym_end
89 \ .'%<'
90 \ .''
91 \ .'%='
92 \ .''
93 \ .'%#'.l:invert_group.'#'
94 \ .g:status_sym_start
95 \ .'%#'.a:highlight_group.'#'.' '
96 \ .'%{&buftype == "" ? "" : &buftype." ".g:status_sym_sep_end." "}'
97 \ .'%{&filetype == "" ? "" :&filetype." ".g:status_sym_sep_end." "}'
98 \ .'%{&spell ? &spelllang." ".g:status_sym_sep_end : ""}'
99 \ .'%{&fileencoding =~ "^$\\|^utf\-8$" ? "" : &fileencoding." ".g:status_sym_sep_end." "}'
100 \ .'%{&fileformat =~ "^$\\|^unix$" ? "" : &fileformat." ".g:status_sym_sep_end}'
101 \ .' '
102 \ .'%cx%-l: '
103 \ .g:status_sym_sep_end
104 \ .' '
105 \ .'%p%% '
106 \ .g:symbol_screen_edge
107 \ .'%#NonText#'
108 endfunction
109
110 function! UpdateTabline(highlight_group)
111 let l:invert_group = CreateInvertGroup(a:highlight_group)
112 let l:git_branch = FugitiveHead()
113 return ''
114 \ .'%#'.a:highlight_group.'#'
115 \ .g:symbol_screen_edge
116 \ .' '
117 \ .'%#'.a:highlight_group.'#'
118 \ .'%-2( %)'
119 \ .'%{fnamemodify(getcwd(-1), ":~")}'
120 \ .' '
121 \ .'%{FugitiveHead() == "" ? "" : g:status_sym_sep_start." ".g:symbol_branch." ".FugitiveHead()}'
122 \ .' '
123 \ .'%#'.l:invert_group.'#'
124 \ .g:status_sym_end
125 \ .'%<'
126 \ .'%='
127 \ .'%#'.l:invert_group.'#'
128 \ .g:status_sym_start
129 \ .'%(%#'.a:highlight_group.'#%)'
130 \ .' '
131 \ .'%-2(%)'
132 \ .'%(%#'.a:highlight_group.'#%)'
133 \ .'%(%{v:servername} %{v:this_session}%)'
134 \ .g:status_sym_sep_end.' '
135 \ .'%-3(%)'
136 \ .'%#'.a:highlight_group.'#'
137 \ .'%{tabpagenr()}/%{tabpagenr()}'
138 \ .' '
139 \ .g:symbol_screen_edge
140 \ .'%##'
141 endfunction
142
143
144 if $USER ==? 'root'
145 let highlight_group_root = "ErrorMsg"
146 let invert_group = CreateInvertGroup(highlight_group_root)
147 let g:group_tabline = highlight_group_root
148 endif
149
150 function! ApplyColorScheme()
151 " set termguicolors | " When on, uses highlight-guifg and highlight-guibg attributes in the terminal (=24bit color) incompatible with nvim
152 " set t_ut=
153 " set up statusline, global and current window individually
154 set statusline=%!UpdateStatus(g:group_inactive)
155 setlocal statusline=%!UpdateStatus(g:group_active)
156 " set up the tabline (match colors)
157 set tabline=%!UpdateTabline(g:group_tabline)
158
159 " otherwise 'bold' can mess up icon sizes and I do not know why
160 highlight! StatusLine cterm=reverse
161 " exec 'highlight! User3 guifg=#D2A032 guibg='.l:fgcolor
162
163 " workaround for VertSplit looking as a repeated slash, because its an
164 " italic bar...
165 highlight! VertSplit gui=NONE cterm=NONE term=NONE
166 endfunction
167 call ApplyColorScheme()
168
169 " apply colors from the loaded colorscheme...
170 " when changing the colorscheme also apply new colors to the statusbar...
171 autocmd ColorScheme * call ApplyColorScheme()
172 autocmd WinEnter * setlocal statusline=%!UpdateStatus(g:group_active)
173 autocmd WinLeave * setlocal statusline<
174augroup END " MAX_FANCYLINE
175
176" vim: shiftwidth=4 tabstop=4 expandtab softtabstop=4
..