I have this in my .vimrc:

nnoremap <C-a> :set relativenumber!<cr>

This toggles the relative number feature only in the current window.

Is it possible to toggle it in all opened windows with one command?

  • You might want to add <silent> to your mapping, so that the :set (or :windo) Ex command doesn't appear in the command line when you use it. Note also that the <C-a> keystroke is a pretty useful command (increment number, in your buffer, if you have one under the cursor of the current line), so think twice before shadowing with a mapping of your own. Cheers!
    – filbranden
    Commented Sep 18, 2020 at 13:23

1 Answer 1


Yes, using :h :windo:

nnoremap <C-a> :windo set relativenumber!<CR>
  • 2
    Thanks. I think <cr> is missing Commented Sep 18, 2020 at 13:19
  • 1
    Yes! Thank you, it's fixed. Commented Sep 18, 2020 at 13:19

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.