I'd like a simple augroup that switches all buffers to absolute line numbers (for Ex commands) when I go into the command window
my current code is:
augroup cmdWin
autocmd!
autocmd CmdwinEnter * setglobal nornu
autocmd CmdwinLeave * setglobal rnu
augroup END
but this doesn't seem to work.
:setglobal
won't work, because it just sets the future default, but doesn't update the values in existing windows. You need to apply this for all current windows, normally with :windo
, but changing windows is a bad idea when the special command-line window is involved. Therefore, we toggle the option(s) "at a distance" via setwinvar()
and a loop:
augroup cmdWin
autocmd!
autocmd CmdwinEnter * for i in range(1,winnr('$')) | call setwinvar(i, '&number', 1) | call setwinvar(i, '&relativenumber', 0) | endfor
autocmd CmdwinLeave * for i in range(1,winnr('$')) | call setwinvar(i, '&number', 0) | call setwinvar(i, '&relativenumber', 1) | endfor
augroup END
This toggles between nu + nornu
and nonu + rnu
; adapt the logic if you want to keep nu
on and just toggle rnu
.
I'd recommend to look at two vim plugins:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With