mode: add several new modes

fixes #2499 #2498
This commit is contained in:
Christian Brabandt 2022-02-06 22:06:11 +01:00
parent 031e6ee4b2
commit 24f2878080
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
2 changed files with 74 additions and 38 deletions

View File

@ -222,33 +222,33 @@ function! airline#check_mode(winnr)
if get(w:, 'airline_active', 1)
let m = mode(1)
if m ==# "i"
let mode = ['insert']
elseif m[0] ==# "i"
let mode = ['insert']
elseif m ==# "Rv"
let mode =['replace']
elseif m[0] ==# "R"
let mode = ['replace']
elseif m[0] =~# '\v(v|V||s|S|)'
let mode = ['visual']
elseif m ==# "t"
let mode = ['terminal']
elseif m[0] ==# "c"
let mode = ['commandline']
elseif m ==# "no" " does not work, most likely, Vim does not refresh the statusline in OP mode
let mode = ['normal']
elseif m[0:1] ==# 'ni'
let mode = ['insert']
let m = 'ni'
" Refer :help mode() to see the list of modes
" NB: 'let mode' here refers to the display colour _groups_,
" not the literal mode's code (i.e., m). E.g., Select modes
" v, S and ^V use 'visual' since they are of similar ilk.
" Some modes do not get recognised for status line purposes:
" no, nov, noV, no^V, !, cv, and ce.
" Mode name displayed is handled in init.vim (g:airline_mode_map).
"
if m[0] ==# "i"
let mode = ['insert'] " Insert modes + submodes (i, ic, ix)
elseif m[0] == "R"
let mode = ['replace'] " Replace modes + submodes (R, Rc, Rv, Rx) (NB: case sensitive as 'r' is a mode)
elseif m[0] =~ '\v(v|V||s|S|)'
let mode = ['visual'] " Visual and Select modes (v, V, ^V, s, S, ^S))
elseif m ==# "t"
let mode = ['terminal'] " Terminal mode (only has one mode (t))
elseif m[0] =~ '\v(c|r|!)'
let mode = ['commandline'] " c, cv, ce, r, rm, r? (NB: cv and ce stay showing as mode entered from)
else
let mode = ['normal']
let mode = ['normal'] " Normal mode + submodes (n, niI, niR, niV; plus operator pendings no, nov, noV, no^V)
endif
if exists("*VMInfos") && !empty(VMInfos())
" Vim plugin Multiple Cursors https://github.com/mg979/vim-visual-multi
let m = 'multi'
endif
if index(['Rv', 'no', 'ni', 'ix', 'ic', 'multi'], m) == -1
" Adjust to handle additional modes, which don't display correctly otherwise
if index(['niI', 'niR', 'niV', 'ic', 'ix', 'Rc', 'Rv', 'Rx', 'multi'], m) == -1
let m = m[0]
endif
let w:airline_current_mode = get(g:airline_mode_map, m, m)

View File

@ -32,27 +32,63 @@ function! airline#init#bootstrap()
call s:check_defined('g:airline_exclude_filetypes', [])
call s:check_defined('g:airline_exclude_preview', 0)
" If g:airline_mode_map_codes is set to 1 in your .vimrc it will display
" only the modes' codes in the status line. Refer :help mode() for codes.
" That may be a preferred presentation because it is minimalistic.
call s:check_defined('g:airline_mode_map_codes', 0)
call s:check_defined('g:airline_mode_map', {})
call extend(g:airline_mode_map, {
if g:airline_mode_map_codes != 1
" If you prefer different mode names than those below they can be
" customised by inclusion in your .vimrc - for example, including just:
" let g:airline_mode_map = {
" \ 'Rv' : 'VIRTUAL REPLACE',
" \ 'niV' : 'VIRTUAL REPLACE (NORMAL)',
" \ }
" ...would override 'Rv' and 'niV' below respectively.
call extend(g:airline_mode_map, {
\ '__' : '------',
\ 'c' : 'COMMAND',
\ 'i' : 'INSERT',
\ 'ic' : 'INSERT COMPL',
\ 'ix' : 'INSERT COMPL',
\ 'multi' : 'MULTI',
\ 'n' : 'NORMAL',
\ 'ni' : '(INSERT)',
\ 'n' : 'NORMAL',
\ 'no' : 'OP PENDING',
\ 'R' : 'REPLACE',
\ 'Rv' : 'V REPLACE',
\ 's' : 'SELECT',
\ 'S' : 'S-LINE',
\ '' : 'S-BLOCK',
\ 't' : 'TERMINAL',
\ 'v' : 'VISUAL',
\ 'V' : 'V-LINE',
\ 'nov' : 'OP PENDING CHAR',
\ 'noV' : 'OP PENDING LINE',
\ 'no' : 'OP PENDING BLOCK',
\ 'niI' : 'INSERT (NORMAL)',
\ 'niR' : 'REPLACE (NORMAL)',
\ 'niV' : 'V REPLACE (NORMAL)',
\ 'v' : 'VISUAL',
\ 'V' : 'V-LINE',
\ '' : 'V-BLOCK',
\ }, 'keep')
\ 's' : 'SELECT',
\ 'S' : 'S-LINE',
\ '' : 'S-BLOCK',
\ 'i' : 'INSERT',
\ 'ic' : 'INSERT COMPL GENERIC',
\ 'ix' : 'INSERT COMPL',
\ 'R' : 'REPLACE',
\ 'Rc' : 'REPLACE COMP GENERIC',
\ 'Rv' : 'V REPLACE',
\ 'Rx' : 'REPLACE COMP',
\ 'c' : 'COMMAND',
\ 'cv' : 'VIM EX',
\ 'ce' : 'EX',
\ 'r' : 'PROMPT',
\ 'rm' : 'MORE PROMPT',
\ 'r?' : 'CONFIRM',
\ '!' : 'SHELL',
\ 't' : 'TERMINAL',
\ 'multi' : 'MULTI',
\ }, 'keep')
" NB: no*, cv, ce, r? and ! do not actually display
else
" Exception: The control character in ^S and ^V modes' codes
" break the status line if allowed to render 'naturally' so
" they are overridden with ^ (when g:airline_mode_map_codes = 1)
call extend(g:airline_mode_map, {
\ '' : '^V',
\ '' : '^S',
\ }, 'keep')
endif
call s:check_defined('g:airline_theme_map', {})
call extend(g:airline_theme_map, {