From 64ecfbab9fc094ec74b429019645e27a34387cb6 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Sun, 24 Jun 2018 12:53:54 +0200 Subject: Tidied the statusline function up --- vimrc-full | 170 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 83 insertions(+), 87 deletions(-) diff --git a/vimrc-full b/vimrc-full index e334071..9d0e605 100644 --- a/vimrc-full +++ b/vimrc-full @@ -1120,6 +1120,26 @@ augroup status 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#") @@ -1135,104 +1155,80 @@ augroup status return l:retval endfunction - function ModeString() - return 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()) - 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\ %{ModeString()}%)" - \ .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\"\ ?\ b:term_title\ :\ 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%%" + \ ."%#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\"\ ?\ b:term_title\ :\ 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 + \ ."%#".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 - let g:symbol_branch = '' - let g:status_sym_start = '' - let g:status_sym_end = '' - let g:status_sym_sep_start = '' - let g:status_sym_sep_end = '' - - if &term == "linux" - let g:group_active = "StatusLineTerm" - let g:group_inactive = "StatusLineTermNC" - let g:group_tabline = "StatusLineTerm" - else - let g:symbol_branch = '' - - let g:group_active = "StatusLine" - let g:group_inactive = "StatusLineNC" - let g:group_tabline = "TabLine" - endif - - - function ApplyColorScheme() + 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) @@ -1245,4 +1241,4 @@ augroup status autocmd WinEnter * setlocal statusline=%!UpdateStatus(g:group_active) autocmd WinLeave * setlocal statusline< -augroup END +augroup END " status -- cgit v1.2.3