:setglobal will not work because it just sets future defaults, but does not update the values ββin existing windows. You need to apply this to all current windows, usually with :windo , but changing windows is a bad idea when a special command line window is involved. Therefore, we switch the option "at a distance" through setwinvar() and the 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 switches between nu + nornu and nonu + rnu ; adapt the logic if you want to enable nu and just switch rnu .
source share