diff options
author | Max Christian Pohle | 2018-06-24 12:53:54 +0200 |
---|---|---|
committer | Max Christian Pohle | 2018-06-24 12:53:54 +0200 |
commit | 64ecfbab9fc094ec74b429019645e27a34387cb6 (patch) | |
tree | f680a345a6941a765558fe3bb8b4048e59baef8f | |
parent | 61b489ddf515ac27a7c6ea9ec329182df96e2b1f (diff) | |
download | vim-64ecfbab9fc094ec74b429019645e27a34387cb6.tar.bz2 vim-64ecfbab9fc094ec74b429019645e27a34387cb6.zip |
Tidied the statusline function up
-rw-r--r-- | vimrc-full | 170 |
1 files changed, 83 insertions, 87 deletions
@@ -1120,6 +1120,26 @@ augroup status | |||
1120 | set noshowmode | " mode will be shown twice, in lightline and below, so we want to deactivate one | 1120 | set noshowmode | " mode will be shown twice, in lightline and below, so we want to deactivate one |
1121 | set laststatus=2 | " required by AirLine and Lightline, without status line does not appear until a window split | 1121 | set laststatus=2 | " required by AirLine and Lightline, without status line does not appear until a window split |
1122 | 1122 | ||
1123 | let g:status_sym_start = '' | ||
1124 | let g:status_sym_end = '' | ||
1125 | let g:status_sym_sep_start = '' | ||
1126 | let g:status_sym_sep_end = '' | ||
1127 | let g:symbol_branch = '' | ||
1128 | |||
1129 | if &term == "linux" | ||
1130 | let g:symbol_branch = '' | ||
1131 | |||
1132 | let g:group_active = "StatusLineTerm" | ||
1133 | let g:group_inactive = "StatusLineTermNC" | ||
1134 | let g:group_tabline = "StatusLineTerm" | ||
1135 | else | ||
1136 | let g:group_active = "StatusLine" | ||
1137 | let g:group_inactive = "StatusLineNC" | ||
1138 | let g:group_tabline = "TabLine" | ||
1139 | endif | ||
1140 | |||
1141 | " this function reverts foreground color and background color of a given | ||
1142 | " highlight group and returns the name of a newly created _invert group | ||
1123 | function! CreateInvertGroup(highlight_group) | 1143 | function! CreateInvertGroup(highlight_group) |
1124 | if(synIDattr(hlID(a:highlight_group), "reverse")==1) | 1144 | if(synIDattr(hlID(a:highlight_group), "reverse")==1) |
1125 | let w:color=synIDattr(hlID(a:highlight_group), "fg#") | 1145 | let w:color=synIDattr(hlID(a:highlight_group), "fg#") |
@@ -1135,104 +1155,80 @@ augroup status | |||
1135 | return l:retval | 1155 | return l:retval |
1136 | endfunction | 1156 | endfunction |
1137 | 1157 | ||
1138 | function ModeString() | ||
1139 | return get({ | ||
1140 | \ 'n' : 'normal', | ||
1141 | \ 'i' : 'insert', | ||
1142 | \ 'R' : 'replace', | ||
1143 | \ 'v' : 'visual', | ||
1144 | \ "V" : 'visual line', | ||
1145 | \ "\<C-V>" : 'visual block', | ||
1146 | \ 'c' : 'command', | ||
1147 | \ 's' : 'select', | ||
1148 | \ 'S' : 'select line', | ||
1149 | \ "\<C-s>" : 'select block', | ||
1150 | \ 't' : 'terminal' | ||
1151 | \ }, mode(), mode()) | ||
1152 | endfunction | ||
1153 | |||
1154 | function! UpdateStatus(highlight_group) | 1158 | function! UpdateStatus(highlight_group) |
1155 | let l:invert_group = CreateInvertGroup(a:highlight_group) | 1159 | let l:invert_group = CreateInvertGroup(a:highlight_group) |
1160 | let l:mode = get({ | ||
1161 | \ 'n' : 'normal', | ||
1162 | \ 'i' : 'insert', | ||
1163 | \ 'R' : 'replace', | ||
1164 | \ 'v' : 'visual', | ||
1165 | \ "V" : 'visual line', | ||
1166 | \ "\<C-V>" : 'visual block', | ||
1167 | \ 'c' : 'command', | ||
1168 | \ 's' : 'select', | ||
1169 | \ 'S' : 'select line', | ||
1170 | \ "\<C-s>" : 'select block', | ||
1171 | \ 't' : 'terminal' | ||
1172 | \ }, mode(), mode()) | ||
1156 | return '' | 1173 | return '' |
1157 | \ ."%#StatusLineHighlight#" | 1174 | \ ."%#StatusLineHighlight#" |
1158 | \ ."%#".a:highlight_group."#" | 1175 | \ ."%#".a:highlight_group."#" |
1159 | \ ."%(%w%h%q\ %{ModeString()}%)" | 1176 | \ ."%(%w%h%q%)".' '.l:mode.' ' |
1160 | \ .g:status_sym_sep_start.' ' | 1177 | \ .g:status_sym_sep_start.' ' |
1161 | \ ."%{(argc()>0\ ?\ argidx()+1.':'.argc().' '.g:status_sym_sep_start.' '\ :\ '')}" | 1178 | \ ."%{(argc()>0\ ?\ argidx()+1.':'.argc().' '.g:status_sym_sep_start.' '\ :\ '')}" |
1162 | \ ."%{winbufnr(0).' '.g:status_sym_sep_start}" | 1179 | \ ."%{winbufnr(0).' '.g:status_sym_sep_start}" |
1163 | \ ."%{(&readonly\ ?\ '\ \ \ '\ :\ '')}" | 1180 | \ ."%{(&readonly\ ?\ '\ \ \ '\ :\ '')}" |
1164 | \ ."%{(&modified\ ?\ nr2char(0xF0C7).'\ '\ :\ '')\ }" | 1181 | \ ."%{(&modified\ ?\ nr2char(0xF0C7).'\ '\ :\ '')\ }" |
1165 | \ ."%{(haslocaldir() ?\ ' '.fnamemodify(getcwd(),\ ':.').' '.nr2char(0xe0b1)\ \:\ '')}\ " | 1182 | \ ."%{(haslocaldir() ?\ ' '.fnamemodify(getcwd(),\ ':.').' '.nr2char(0xe0b1)\ \:\ '')}\ " |
1166 | \ ."%{(&buftype\ ==\ \"terminal\"\ ?\ b:term_title\ :\ substitute(expand('%:p'),\ '^'.getcwd(-1).'/*',\ '',\ ''))\ }" | 1183 | \ ."%{(&buftype\ ==\ \"terminal\"\ ?\ b:term_title\ :\ substitute(expand('%:p'),\ '^'.getcwd(-1).'/*',\ '',\ ''))\ }" |
1167 | \ ."%1(%)" | 1184 | \ ."%1(%)" |
1168 | \ ."%#".l:invert_group."#" | 1185 | \ ."%#".l:invert_group."#" |
1169 | \ .g:status_sym_end | 1186 | \ .g:status_sym_end |
1170 | \ .'' | 1187 | \ .'' |
1171 | \ ."%=" | 1188 | \ ."%=" |
1172 | \ .'' | 1189 | \ .'' |
1173 | \ ."%#".l:invert_group."#" | 1190 | \ ."%#".l:invert_group."#" |
1174 | \ .g:status_sym_start | 1191 | \ .g:status_sym_start |
1175 | \ ."%#".a:highlight_group."#" | 1192 | \ ."%#".a:highlight_group."#" |
1176 | \ ."%1(%)" | 1193 | \ ."%1(%)" |
1177 | \ ."%{(&filetype\ !=\ ''\ ?\ &filetype\ :\ &buftype)}" | 1194 | \ ."%{(&filetype\ !=\ ''\ ?\ &filetype\ :\ &buftype)}" |
1178 | \ ."%(\ %{g:status_sym_sep_end}\ %)" | 1195 | \ ."%(\ %{g:status_sym_sep_end}\ %)" |
1179 | \ ."%{(&spell\ ?\ &spelllang.' '.g:status_sym_sep_end\ :\ '')}" | 1196 | \ ."%{(&spell\ ?\ &spelllang.' '.g:status_sym_sep_end\ :\ '')}" |
1180 | \ ."%{(&fileencoding\ !=\ ''\ ?\ &fileencoding.' '.g:status_sym_sep_end.' '\ :\ '')}" | 1197 | \ ."%{(&fileencoding\ !=\ ''\ ?\ &fileencoding.' '.g:status_sym_sep_end.' '\ :\ '')}" |
1181 | \ ."%{(&fileformat\ !=\ ''\ ?\ ' '.&fileformat.' '\ :\ '')}" | 1198 | \ ."%{(&fileformat\ !=\ ''\ ?\ ' '.&fileformat.' '\ :\ '')}" |
1182 | \ .g:status_sym_sep_end.' ' | 1199 | \ .g:status_sym_sep_end.' ' |
1183 | \ ."%4l:%-3c" | 1200 | \ ."%4l:%-3c" |
1184 | \ .g:status_sym_sep_end.' ' | 1201 | \ .g:status_sym_sep_end.' ' |
1185 | \ ."%-3p%%" | 1202 | \ ."%-3p%%" |
1186 | endfunction | 1203 | endfunction |
1187 | 1204 | ||
1188 | function! UpdateTabline(highlight_group) | 1205 | function! UpdateTabline(highlight_group) |
1189 | let l:invert_group = CreateInvertGroup(a:highlight_group) | 1206 | let l:invert_group = CreateInvertGroup(a:highlight_group) |
1190 | return '' | 1207 | return '' |
1191 | \ ."%#".a:highlight_group."#" | 1208 | \ ."%#".a:highlight_group."#" |
1192 | \ ."%3( \ %)" | 1209 | \ ."%3( \ %)" |
1193 | \ ."%{getcwd(-1)}" | 1210 | \ ."%{getcwd(-1)}" |
1194 | \ .g:status_sym_sep_start.' ' | 1211 | \ .g:status_sym_sep_start.' ' |
1195 | \ ."%(\ ".g:symbol_branch."\ %{fugitive#head()}\ %)" | 1212 | \ ."%(\ ".g:symbol_branch."\ %{fugitive#head()}\ %)" |
1196 | \ ."%#".l:invert_group."#" | 1213 | \ ."%#".l:invert_group."#" |
1197 | \ .g:status_sym_end | 1214 | \ .g:status_sym_end |
1198 | \ .'' | 1215 | \ .'' |
1199 | \ ."%=" | 1216 | \ ."%=" |
1200 | \ .'' | 1217 | \ .'' |
1201 | \ ."%#".l:invert_group."#" | 1218 | \ ."%#".l:invert_group."#" |
1202 | \ .g:status_sym_start | 1219 | \ .g:status_sym_start |
1203 | \ ."%#".a:highlight_group."#" | 1220 | \ ."%#".a:highlight_group."#" |
1204 | \ ."%3(\ %)" | 1221 | \ ."%3(\ %)" |
1205 | \ ."%(%{v:servername}\ %{v:this_session}%)" | 1222 | \ ."%(%{v:servername}\ %{v:this_session}%)" |
1206 | \ .g:status_sym_sep_end.' ' | 1223 | \ .g:status_sym_sep_end.' ' |
1207 | \ ."%(\ \ %{tabpagenr()}/%{tabpagenr('$')}\ %)" | 1224 | \ ."%(\ \ %{tabpagenr()}/%{tabpagenr('$')}\ %)" |
1208 | \ ."%##" | 1225 | \ ."%##" |
1209 | \ ."" " end | 1226 | \ ."" " end |
1210 | endfunction | 1227 | endfunction |
1211 | 1228 | ||
1212 | let g:symbol_branch = '' | 1229 | function! ApplyColorScheme() |
1213 | let g:status_sym_start = '' | ||
1214 | let g:status_sym_end = '' | ||
1215 | let g:status_sym_sep_start = '' | ||
1216 | let g:status_sym_sep_end = '' | ||
1217 | |||
1218 | if &term == "linux" | ||
1219 | let g:group_active = "StatusLineTerm" | ||
1220 | let g:group_inactive = "StatusLineTermNC" | ||
1221 | let g:group_tabline = "StatusLineTerm" | ||
1222 | else | ||
1223 | let g:symbol_branch = '' | ||
1224 | |||
1225 | let g:group_active = "StatusLine" | ||
1226 | let g:group_inactive = "StatusLineNC" | ||
1227 | let g:group_tabline = "TabLine" | ||
1228 | endif | ||
1229 | |||
1230 | |||
1231 | function ApplyColorScheme() | ||
1232 | " set termguicolors | " When on, uses highlight-guifg and highlight-guibg attributes in the terminal (=24bit color) incompatible with nvim | 1230 | " set termguicolors | " When on, uses highlight-guifg and highlight-guibg attributes in the terminal (=24bit color) incompatible with nvim |
1233 | " set t_ut= | 1231 | " set t_ut= |
1234 | " | ||
1235 | " | ||
1236 | " set up statusline, global and current window individually | 1232 | " set up statusline, global and current window individually |
1237 | set statusline=%!UpdateStatus(g:group_inactive) | 1233 | set statusline=%!UpdateStatus(g:group_inactive) |
1238 | setlocal statusline=%!UpdateStatus(g:group_active) | 1234 | setlocal statusline=%!UpdateStatus(g:group_active) |
@@ -1245,4 +1241,4 @@ augroup status | |||
1245 | 1241 | ||
1246 | autocmd WinEnter * setlocal statusline=%!UpdateStatus(g:group_active) | 1242 | autocmd WinEnter * setlocal statusline=%!UpdateStatus(g:group_active) |
1247 | autocmd WinLeave * setlocal statusline< | 1243 | autocmd WinLeave * setlocal statusline< |
1248 | augroup END | 1244 | augroup END " status |