When I was not sure about how to do this, I asked this question on StackOverflow, the body of which is the following:
As regards line numbers, when doing normal file editing, I prefer to have the following setting
set number set relativenumber
because the former tells me where I am, the latter helps me using j and k effectively.
However, when debugging with
gdb, using the
termdebugpackage and the
:Termdebugcommand, I often want to set breakpoints; hence, I'd like to turn the latter option off, executing the
set norelativenumbercommand on a global scope, so that all files I'm editing show the actual line numbers.
Reading the answer, and Vim help pages a bit more, I ended up with the following solution, which is now part of my
" Source the termdebug plugin packadd termdebug " Add mapping to load termdebug noremap <silent> <Leader>td :call MyTermdebug()<CR> " turn off relativenumber, " start Termdebug, " and create autocmd to turn relativenumber back on function! MyTermdebug() call SetRelNumInAllWin(v:false) augroup ClosingDebugger au! autocmd BufUnload !gdb call SetRelNumInAllWin(v:true) augroup END Termdebug endfunction " set/unset relativenumber in all windows if flag is v:true/v:false function! SetRelNumInAllWin(flag) let current_win_id = win_getid() tabdo windo call SetRelNum(a:flag) call win_gotoid(current_win_id) endfunction " set/unset relativenumber in current window if flag is v:true/v:false function! SetRelNum(flag) if &number if a:flag set relativenumber else set norelativenumber end end endfunction