1

mode() won't return anything when I go into Command mode. I use this for StatusLine info:

set statusline+=%{mode()} as a test to see what mode() returns.

pressing c or C and my StatusLine stays as NORMAL. Is this a bug or am I doing something wrong? The other modes seem to work normally.

Below is the code:

set statusline+=\ %{g:mode_map[mode()]}

let g:mode_map = {
    \ 'c'      : ' COMMAND ',
    \ 'i'      : ' INSERT ',
    \ 'ic'     : ' INSERT ',
    \ 'ix'     : ' INSERT ',
    \ 'n'      : ' NORMAL ',
    \ 'multi'  : ' MULTI ',
    \ 'ni'     : ' NORMAL ',
    \ 'no'     : ' NORMAL ',
    \ 'R'      : ' REPLACE ',
    \ 'r'      : ' Replace ',
    \ 'Rv'     : ' REPLACE ',
    \ 's'      : ' SELECT ',
    \ 'S'      : ' SELECT ',
    \ ''       : ' SELECT ',
    \ 't'      : ' TERMINAL ',
    \ 'v'      : ' VISUAL ',
    \ 'V'      : ' VISUAL ',
    \ '^V'       : ' VISUAL ',
}
3
  • fwiw that works fine on my setup ubuntu + neovim 0.5/vim 8.2
    – statox
    Mar 31 at 14:33
  • I think it is merely that vim does not redraw when pressing :. You can see this with cnoremap <c-l> <c-r>=execute('redraw!')<cr>
    – Mass
    Mar 31 at 14:48
  • Welcome to Vi and Vim!
    – D. Ben Knoble
    Mar 31 at 16:54
2

The stuff is known to work in Neovim, but not in Vim, because Vim is too lazy when updating screen, as @Mass correctly noted in the comments.

Personally, I just don't pay attention to this, and keep using my status line plugin without any worries.

But if you are so eager to fix it, you need to force status line redrawing, e.g.:

augroup test | au!
    autocmd CmdlineEnter : redrawstatus
augroup end
1
  • I did this soon after getting your email and it worked like a charm. THX
    – TonyB
    Apr 1 at 15:02
0

FIXED! This did it for me;

" add this so COMMAND will show when changing to command mode.
" leave the bang '!' off if updates for other windows is not required
augroup my_statusline | autocmd!
    autocmd CmdlineEnter * redrawstatus!
augroup END

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.