How to add a space between the line numbers and text content in Emacs?

I use Emacs in console. The linum-mode displays the line numbers just well. However, in the console, there is no space between the line numbers and the text content, which makes it a little messy some times. How to add a space between the line numbers and text content in Emacs?

If you are using the linum-mode for displaying the line numbers, you can define your own linum-format to specify the format by adding the space in your ~/.emacs:

(require 'linum)
(global-linum-mode t)
;; use customized linum-format: add a addition space after the line number                                                                      
(setq linum-format (lambda (line) (propertize (format (let ((w (length (number-to-string (count-lines (point-min) (point-max)))))) (concat "%" 
(number-to-string w) "d ")) line) 'face 'linum)))
Answered by Eric Z Ma.

Eric Z Ma

Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *