How to set and unset relativenumber to all buffers?

Viewed 249

As regards line numbers, when doing normal file editing, I prefer to have the following setting

set number
set relativenumber

because the formers tells me where I am, the latter helps me using j and k effectively.

However, when debugging with gdb, I often want to set breakpoints; hence, I'd like to turn the latter option off, executing the set norelativenumber command on a global scope, so that all files I'm editing show the actual line numbers.

In this respect,

  • I kinda know how to trigger the action (when I execute the :Termdebug command, I should also execute set norelativenumber),
  • but, this is the question, I don't know how to apply that setting to all the buffer (well, not all the buffer, as I don't need numbers in the gdb window, nor in the program's output window, nor in the help, if I open one, and so on);
  • furthermore, I'm not sure how to handle the case that I quit the debugger (in that case I should set again set relativenumber globally).
2 Answers

The answer from Csaba Dunai is useful as far as it gives a link and some feed for thoughts.

On the other hand, the proposed solution is not really the solution, for the simple reason (I had not thought about this) that number and relativenumber are not local to buffers but local to windows. Therefore, if windows are open in more tabs, the command to go is the following:

tabdo windo set norelativenumber

As regards the complete workflow that I was thinking about, I came up with a solution which seems to work pretty well for the time being. It is in code review here.

Related