The built-in line numbering mechanism uses the text-area that is sandwiched between the left/right fringes and/or left/right margins, to the extent that fringes/margins exist. [What happens internally is that the line number glyphs (with a space on each end) are prepended to the glyphs of the display line within the text area.] Thus, setting the fringe or margin values will have no effect on the width of built-in line numbers. The manual has a useful diagram of the window layout, which illustrates where the text area is in relation to the fringes and margins: https://www.gnu.org/software/emacs/manual/html_node/elisp/Window-Sizes.html
display-line-numbers-width is a variable defined in
C source code. The default value is
nil. It automatically becomes buffer-local when set. Documentation:
Minimum width of space reserved for line number display.
A positive number means reserve that many columns for line numbers,
even if the actual number needs less space.
The default value of nil means compute the space dynamically.
Any other value is treated as nil.
To set it on buffer-local basis, use:
(setq display-line-numbers-width VALUE)
To set a default global value, use:
(setq-default display-line-numbers-width VALUE)
In the event that anyone is curious about the code that places a space glyph (padding) to the left/right of the built-in line numbers, the code is in
xdisp.c within the function
pint2str (lnum_buf, it->lnum_width + 1, lnum_to_display);
strcat (lnum_buf, " ");
To eliminate the left/right padding, we could make the following changes and build Emacs from source:
pint2str (lnum_buf, it->lnum_width, lnum_to_display);
// strcat (lnum_buf, " ");
However, fiddling with the display engine should probably best be left to Emacs developers as it is a rather complex piece of machinery.