I have

  au InsertEnter * set norelativenumber
  au InsertLeave * set relativenumber

So that I have relativenumber in normal mode but not insert mode. I want to extend this to command mode. I tried

  au CmdLineEnter * set norelativenumber
  au CmdlineLeave * set relativenumber

But these don't work. Under h CmdLineEnter, it says

<afile> is set to the |cmdline-char|.

So I think it's setting norelativenumber on the : "file", which isn't my actual buffer. How do I get it to set norelativenumber on the buffer I entered the command line from?

I'm on neovim 0.4.2.

1 Answer 1


This seems to work:

au CmdLineEnter * set norelativenumber | redraw
au CmdlineLeave * set relativenumber

Edit: apparently the window does not redraw while you are in the command mode, so you need to force the redraw explicitly to get the effect of the command to be shown. And apparently you also do not need | redraw for CmdlineLeave case, because when you leave the command line mode, you're back in the window, and it redraws automatically (so I've removed the second | redraw in the example above, leaving it only for CmdLineEnter)

  • Welcome to Vi and Vim! If you know why this works, an edit with the explanation would be awesome :)
    – D. Ben Knoble
    Nov 12, 2020 at 23:07
  • Unfortunately, I don't. I'm not an expert in vimscript. First I thought that this was about the rno command not being executed in the correct window, so I've concocted a function that did execute(winnr() . 'windo ' . a:cmd) to execute set rno/sent norno commands. But then it too didn't work. After experimenting it became clear that comands are executed in correct window, but just that the view of the window didn't change. Then I thought that maybe it just do not redraw while I am in a command mode. Added redraw and it worked, and it turned out the function with windo is not needed Nov 13, 2020 at 3:53

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.