From f2e01d7e513067ddb57c75f6e38cdcf434946cf8 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Mon, 22 Oct 2018 00:02:58 +0200 Subject: Major refactoring for version 2.0 vim-plug has been removed and replaced with Vims internal bundle mechanism. But I already noticed, that there is also GLVM now and started trying that as well. --- plugin/statusline.vim | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 plugin/statusline.vim (limited to 'plugin/statusline.vim') 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 @@ +augroup MAX_FANCYLINE + set noshowmode | " mode will be shown twice, in lightline and below, so we want to deactivate one + set laststatus=2 | " required by AirLine and Lightline, without status line does not appear until a window split + + let g:status_sym_start = '' + let g:status_sym_end = '' + let g:status_sym_sep_start = '' + let g:status_sym_sep_end = '' + let g:symbol_branch = '' + + if &term == "linux" + let g:symbol_branch = '' + + let g:group_active = "StatusLineTerm" + let g:group_inactive = "StatusLineTermNC" + let g:group_tabline = "StatusLineTerm" + else + let g:group_active = "StatusLine" + let g:group_inactive = "StatusLineNC" + let g:group_tabline = "TabLine" + endif + + " this function reverts foreground color and background color of a given + " highlight group and returns the name of a newly created _invert group + function! CreateInvertGroup(highlight_group) + if(synIDattr(hlID(a:highlight_group), "reverse")==1) + let w:color=synIDattr(hlID(a:highlight_group), "fg#") + else + let w:color=synIDattr(hlID(a:highlight_group), "bg#") + endif + + let l:retval=a:highlight_group.'_invert' + if(exists('w:color') && w:color == '') + let w:color = 'NONE' + endif + silent! exec 'highlight '.retval.' gui=NONE guifg='.w:color.' cterm=NONE ctermfg='.w:color + return l:retval + endfunction + + function! UpdateStatus(highlight_group) + let l:invert_group = CreateInvertGroup(a:highlight_group) + let l:mode = get({ + \ 'n' : 'normal', + \ 'i' : 'insert', + \ 'R' : 'replace', + \ 'v' : 'visual', + \ "V" : 'visual line', + \ "\" : 'visual block', + \ 'c' : 'command', + \ 's' : 'select', + \ 'S' : 'select line', + \ "\" : 'select block', + \ 't' : 'terminal' + \ }, mode(), mode()) + return '' + \ ."%#StatusLineHighlight#" + \ ."%#".a:highlight_group."#" + \ ."%(%w%h%q%)".' '.l:mode.' '.g:status_sym_sep_start.' ' + \ ."%{(argc()>0\ ?\ argidx()+1.':'.argc().' '.g:status_sym_sep_start.' '\ :\ '')}" + \ ."%{winbufnr(0).' '.g:status_sym_sep_start}" + \ ."%{(&readonly\ ?\ '\ \ 🔒'\ :\ '')}" + \ ."%{(&modified\ ?\ '\ \ '.nr2char(0xF0C7).'\ '\ :\ '')\ }" + \ ."%{(haslocaldir() ?\ fnamemodify(getcwd(),\ ':.').' '.nr2char(0xe0b1)\ \:\ '')}\ " + \ ."%{(&buftype\ ==\ \"terminal\"\ ?\ has('nvim')?b:term_title:expand(&titlestring)\ :\ substitute(expand('%:p'),\ '^'.getcwd(-1).'/*',\ '',\ ''))\ }" + \ ."%1(%)" + \ ."%#".l:invert_group."#" + \ .g:status_sym_end + \ .'' + \ ."%=" + \ .'' + \ ."%#".l:invert_group."#" + \ .g:status_sym_start + \ ."%#".a:highlight_group."#" + \ ."%1(%)" + \ ."%{(&filetype\ !=\ ''\ ?\ &filetype\ :\ &buftype)}" + \ ."%(\ %{g:status_sym_sep_end}\ %)" + \ ."%{(&spell\ ?\ &spelllang.' '.g:status_sym_sep_end\ :\ '')}" + \ ."%{(&fileencoding\ !=\ ''\ ?\ &fileencoding.' '.g:status_sym_sep_end.' '\ :\ '')}" + \ ."%{(&fileformat\ !=\ ''\ ?\ ' '.&fileformat.' '\ :\ '')}" + \ .g:status_sym_sep_end.' ' + \ ."%4l:%-3c" + \ .g:status_sym_sep_end.' ' + \ ."%-3p%%" + endfunction + + function! UpdateTabline(highlight_group) + let l:invert_group = CreateInvertGroup(a:highlight_group) + return '' + \ ."%#".a:highlight_group."#" + \ ."%3( \ %)\ " + \ ."%{getcwd(-1)}\ " + \ .g:status_sym_sep_start.' ' + \ ."%(\ ".g:symbol_branch."\ %{fugitive#head()}\ %)" + \ ."%#".l:invert_group."#" + \ .g:status_sym_end + \ .'' + \ ."%=" + \ .'' + \ ."%#".l:invert_group."#" + \ .g:status_sym_start + \ ."%#".a:highlight_group."#" + \ ."%3(\ %)" + \ ."%(%{v:servername}\ %{v:this_session}%)" + \ .g:status_sym_sep_end.' ' + \ ."%(\ \ %{tabpagenr()}/%{tabpagenr('$')}\ %)" + \ ."%##" + \ ."" " end + endfunction + + function! ApplyColorScheme() + " set termguicolors | " When on, uses highlight-guifg and highlight-guibg attributes in the terminal (=24bit color) incompatible with nvim + " set t_ut= + " set up statusline, global and current window individually + set statusline=%!UpdateStatus(g:group_inactive) + setlocal statusline=%!UpdateStatus(g:group_active) + " set up the tabline (match colors) + set tabline=%!UpdateTabline(g:group_tabline) + endfunction + " apply colors from the loaded colorscheme... + " when changing the colorscheme also apply new colors to the statusbar... + autocmd VimEnter,ColorScheme * call ApplyColorScheme() + + autocmd WinEnter * setlocal statusline=%!UpdateStatus(g:group_active) + autocmd WinLeave * setlocal statusline< +augroup END " MAX_FANCYLINE -- cgit v1.2.3