introduce mode map
This commit is contained in:
parent
fda2171dee
commit
f140b29cb7
@ -23,6 +23,15 @@ let s:airline_colors_normal = g:airline#themes#{g:airline_theme}#normal
|
||||
let s:airline_colors_insert = g:airline#themes#{g:airline_theme}#insert
|
||||
let s:airline_colors_visual = g:airline#themes#{g:airline_theme}#visual
|
||||
|
||||
let s:airline_mode_map = {
|
||||
\ 'n' : ' NORMAL ',
|
||||
\ 'i' : ' INSERT ',
|
||||
\ 'R' : ' RPLACE ',
|
||||
\ 'v' : ' VISUAL ',
|
||||
\ 'V' : ' V-LINE ',
|
||||
\ 'c' : ' CMD ',
|
||||
\ '' : ' V-BLCK ',
|
||||
\ }
|
||||
let s:airline_highlight_map = {
|
||||
\ 'mode' : 'User2',
|
||||
\ 'mode_seperator' : 'User3',
|
||||
@ -47,54 +56,6 @@ function! s:highlight(mode, key)
|
||||
exec cmd
|
||||
endfunction
|
||||
|
||||
function! AirlineModePrefix()
|
||||
let l:mode = mode()
|
||||
|
||||
call <sid>highlight('normal', 'statusline')
|
||||
call <sid>highlight('normal', 'statusline_nc')
|
||||
call <sid>highlight('normal', 'inactive')
|
||||
call <sid>highlight('normal', 'mode')
|
||||
call <sid>highlight('normal', 'mode_seperator')
|
||||
call <sid>highlight('normal', 'info')
|
||||
call <sid>highlight('normal', 'info_seperator')
|
||||
call <sid>highlight('normal', 'file')
|
||||
|
||||
if l:mode ==# "i" || l:mode ==# "R"
|
||||
call <sid>highlight('insert', 'statusline')
|
||||
call <sid>highlight('insert', 'mode')
|
||||
call <sid>highlight('insert', 'mode_seperator')
|
||||
call <sid>highlight('insert', 'info')
|
||||
call <sid>highlight('insert', 'info_seperator')
|
||||
elseif l:mode ==? "v" || l:mode ==# ""
|
||||
call <sid>highlight('visual', 'statusline')
|
||||
call <sid>highlight('visual', 'mode')
|
||||
call <sid>highlight('visual', 'mode_seperator')
|
||||
call <sid>highlight('visual', 'info')
|
||||
call <sid>highlight('visual', 'info_seperator')
|
||||
endif
|
||||
|
||||
if l:mode ==# "n"
|
||||
return " NORMAL "
|
||||
elseif l:mode ==# "i"
|
||||
return " INSERT "
|
||||
elseif l:mode ==# "R"
|
||||
return " RPLACE "
|
||||
elseif l:mode ==# "v"
|
||||
return " VISUAL "
|
||||
elseif l:mode ==# "V"
|
||||
return " V·LINE "
|
||||
elseif l:mode ==# "c"
|
||||
return " CMD "
|
||||
elseif l:mode ==# ""
|
||||
return " V·BLCK "
|
||||
else
|
||||
return l:mode
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" init colors on startup
|
||||
call AirlineModePrefix()
|
||||
|
||||
function! s:update_statusline(active)
|
||||
let l:mode_color = a:active ? "%2*" : "%9*"
|
||||
let l:mode_sep_color = a:active ? "%3*" : "%9*"
|
||||
@ -124,6 +85,41 @@ function! s:update_statusline(active)
|
||||
call setwinvar(winnr(), '&statusline', sl)
|
||||
endfunction
|
||||
|
||||
function! AirlineModePrefix()
|
||||
let l:mode = mode()
|
||||
|
||||
call <sid>highlight('normal', 'statusline')
|
||||
call <sid>highlight('normal', 'statusline_nc')
|
||||
call <sid>highlight('normal', 'inactive')
|
||||
call <sid>highlight('normal', 'mode')
|
||||
call <sid>highlight('normal', 'mode_seperator')
|
||||
call <sid>highlight('normal', 'info')
|
||||
call <sid>highlight('normal', 'info_seperator')
|
||||
call <sid>highlight('normal', 'file')
|
||||
|
||||
if l:mode ==# "i" || l:mode ==# "R"
|
||||
call <sid>highlight('insert', 'statusline')
|
||||
call <sid>highlight('insert', 'mode')
|
||||
call <sid>highlight('insert', 'mode_seperator')
|
||||
call <sid>highlight('insert', 'info')
|
||||
call <sid>highlight('insert', 'info_seperator')
|
||||
elseif l:mode ==? "v" || l:mode ==# ""
|
||||
call <sid>highlight('visual', 'statusline')
|
||||
call <sid>highlight('visual', 'mode')
|
||||
call <sid>highlight('visual', 'mode_seperator')
|
||||
call <sid>highlight('visual', 'info')
|
||||
call <sid>highlight('visual', 'info_seperator')
|
||||
endif
|
||||
|
||||
if has_key(s:airline_mode_map, l:mode)
|
||||
return s:airline_mode_map[l:mode]
|
||||
endif
|
||||
return l:mode
|
||||
endfunction
|
||||
|
||||
" init colors on startup
|
||||
call AirlineModePrefix()
|
||||
|
||||
augroup airline
|
||||
au!
|
||||
autocmd WinLeave * call <sid>update_statusline(0)
|
||||
|
Loading…
Reference in New Issue
Block a user