I am trying to set norelativenumber on CmdlineEnter and relativenumber on CmdlineLeave, but it didn't work. Why is that?

local setup = function()
  augroup SmartNumberGroup
  autocmd CmdlineEnter * set norelativenumber
  autocmd CmdlineLeave * set relativenumber
  augroup END]], true)

return {
  setup = setup

1 Answer 1


You need to use redraw after setting relativenumber with the CmdLineEnter event:

augroup SmartNumberGroup
    autocmd CmdLineEnter * set norelativenumber|redraw
    autocmd CmdLineLeave * set relativenumber
augroup END

I didn't do it in lua but it should work the same. Also note that you probably want to have this behavior happening only when you start a command with : but CmdLineEnter is also triggered by / or ?. So you might want to have this as your autocmd:

autocmd CmdLineEnter * if (v:event.cmdtype == ':') | set norelativenumber | redraw | endif
  • 4
    CmdLineEnter : should work I think Commented May 6, 2021 at 17:54
  • Awesome!!!! But why I don't need to use redraw after relativenumber? Commented May 7, 2021 at 1:19
  • You don’t need redraw after CmdLineLeave because that puts you in normal mode which already redraws the screen.
    – statox
    Commented May 7, 2021 at 20:32
  • Thanks @Christian good point
    – statox
    Commented May 7, 2021 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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