I am using (global-display-line-numbers-mode 1) in my init.el file and everything is working as expected. The only problem is that I find the gutter width to be too wide and would prefer it to match the size that's used when using (linum-mode 1).

I have tried running (setq left-margin-width 10) in my current buffer and it doesn't change anything.

Here is a screen shot of what I mean with linum mode on the left and display-line-numbers-mode on the right:

enter image description here

1 Answer 1


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 maybe_produce_line_number:

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.

  • 1
    So what the documentation is saying is that I can't make it any smaller and have it grow as needed? Setting the value only seems to make the text-area bigger but I can't go smaller.
    – dylanjm
    Commented Aug 21, 2019 at 20:02
  • 1
    I updated the answer to indicate that internally there is a space glyph to the left and right of the line numbers -- that cannot be adjusted by the user. Those spaces could be eliminated by modifying the C internals, but it is not something the majority of users would be interested in hacking. Emacs estimates the minimum columns for line numbers that will be needed for a given window based on its contents, unless the user specifies a fixed value.
    – lawlist
    Commented Aug 21, 2019 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.