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)))

Eric Ma

Eric is a 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.

One comment:

  1. Thanks a lot man, really helpful.

    Since I’m using UTF-8 capable terminals all the times anyways, I put a box drawing character pipe, instead of a blank: “d│”.

    Cheers

Leave a Reply

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