Turning relativenumber option off/on when opening/closing the gdb terminal window
Two things off the top of my head:

Use mode-specific mappings, so nnoremap limits the mapping to normal mode. (Great job on the use of non-recursive mappings.)

You can access options as vimscript variables with &amp;relativenumber. SetRelNum is sort of unecessary: I would have written

tabdo windo let &amp;relativenumber = a:flag


(And if that doesn’t work because of some odd scope rule, you can exec it with everything but a:flag in quotes. You may have to pass 0/1 instead of v:false/v:true etc.)