1

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

local setup = function()
  vim.api.nvim_exec([[
  augroup SmartNumberGroup
  autocmd!
  autocmd CmdlineEnter * set norelativenumber
  autocmd CmdlineLeave * set relativenumber
  augroup END]], true)
end

return {
  setup = setup
}

2

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

augroup SmartNumberGroup
    autocmd!
    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
  • 4
    CmdLineEnter : should work I think – Christian Brabandt May 6 at 17:54
  • Awesome!!!! But why I don't need to use redraw after relativenumber? – John Winston May 7 at 1:19
  • You don’t need redraw after CmdLineLeave because that puts you in normal mode which already redraws the screen. – statox May 7 at 20:32
  • Thanks @Christian good point – statox May 7 at 20:32

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.