For Emacs version >= 26 you should use display-line-numbers-mode or global-display-line-numbers-mode.
As @eric-brown mentioned you can use M-x linum-mode.
Another good idea is to use (add-hook 'prog-mode-hook 'linum-mode) in your init.el to automatically enable linum-mode in all programming modes.
M-x find-library will let you select a library and take you to the source code.
Note that you may not have the elisp files installed on your machine. For Ubuntu, try installing emacs24-el (or whatever version you're on; look for the ...-el to get the elisp source).
If you are using Emacs 26 or newer, you can use display-line-numbers-mode.
** Emacs now supports optional display of line numbers in the buffer. This is similar to what 'linum-mode' provides, but much faster and
doesn't usurp the display margin for the line numbers. Customize the
buffer-local variable 'display-line-numbers' to ...
Like most terminals, Emacs' term has a scrollback limit -- which will naturally mess with the consistency of linum's counting, as lines will be deleted from the beginning of the buffer.
The term-buffer-maximum-size variable controls this, and sure enough it has a default value of 2048.
So linum was telling you the truth: the terminal buffer was never more ...
The problem here is that there’s no face to control the appearance of
the margins. You can display text in the margin using overlays (that’s
what linum-mode does) but, like any text in Emacs, it’s constrained
to the limits of the buffer. So you can’t have any control over the
margin display beyond the last line of the buffer.
What you can do, ...
Linum mode provides the linum-format customizable variable that allows you to format how you want your line numbers to appear. Set this variable to have the value "%x" to get hexadecimal line numbers. This can be done either through the built-in customization process or by running (setq linum-format "%x").
Edit: You may only want to have ...
Because the last line hasn't started yet. Adding newline symbol to the end makes the cursor jump from the current line to the next one, but it doesn't add anything to it (new one). Strictly speaking, it is not a line yet.
Supposing that every newline symbol was visible, you would get
nlinum-mode is another option. It has the same interface as linum-mode, so you can use the same hooks, but it uses a different technology to be more performant. Quote from nlinum.el:
;; This is like linum-mode, but uses jit-lock to be (hopefully) more efficient.
You can install it via GNU Elpa via the usual list-packages.
If you are looking for source of a function <name>, you can find a link to the source in the description of the function:
C-h f <name> RET
In your case it will be:
C-h f linum-mode RET
Starting from Emacs 24.3 C-h f can perform autoloading:
When this command is called for an autoloaded function whose docstring
contains a key substitution ...
The intention behind nlinum.el was to obsolete linum.el but it turns out that some customizations of linum.el can't really be adapted to nlinum.el (mostly the "relative line numbers").
Also the new display-line-numbers-mode in Emacs-26 aims to obsolete both of those. But again, some customizations of nlinum.el and linum.el can't be adapted to display-line-...
Here are two basic options to run a function (in this case, linum-relative-toggle) at start-up.
Simple option: add (linum-relative-toggle) to your init file (probably at the end).
Somewhat more involved option (may be necessary if the simple option doesn't help for some reason): use (add-hook 'after-init-hook #'linum-relative-toggle).
A solution covering nearly every file would be making use of the fact that nearly all buffers for these are derived from text-mode and prog-mode:
(add-hook 'text-mode-hook 'linum-mode)
(add-hook 'prog-mode-hook 'linum-mode)
linum-mode was added in Emacs 23.1. See the related NEWS file, or if you have 23.1+ version of Emacs, you can find this information via C-u C-h n 23.1 then C-s linum.
I know it's 23.1 because I searched linum across all NEWS files.
Certainly linum-mode is a good choice.
If you don't always want to see line numbers, like me, you can use this trick from the excellent What the .emacs.d!? blog.
This temporarily enables linum-mode when you run goto-line.
Here's the code from his blog:
(global-set-key [remap goto-line] 'goto-line-with-feedback)
(defun goto-line-with-feedback () "Show ...
There are a few ways to do this -- my preferred method is to set the frame defaults for the fringes:
(set-face-attribute 'fringe nil :background "red")
(add-to-list 'default-frame-alist '(left-fringe . 11))
(add-to-list 'default-frame-alist '(right-fringe . 0))
It is possible to set the windows fringes globally:
(setq-default left-fringe-width 11)
Line numbers (of the kind that's displayed as a strip with every line number on a window's side) are known for their performance and redrawing issues. One of them is that they're using the display margin which interferes with other packages that (indirectly) manipulate the margins.
The more prominent examples would be auto-complete-mode and company-mode. ...
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 ...
I would highly recommend against editing linum.el. The huge disadvantage of doing that is that your changes will be lost every time the package gets updated. Also, that page you linked said you can achieve the same effect without editing linum.el by doing this:
(setq linum-format “%d “)
The linum-off.el file by Matthew Fidler should be what you are looking for.
Here is a copy of his code:
(defcustom linum-disabled-modes-list '(eshell-mode wl-summary-mode compilation-mode org-mode text-mode dired-mode doc-view-mode image-mode)
"* List of modes disabled when global linum mode is on"
:type '(repeat (sexp :tag "Major ...
This is what I put in my init.el file to fix the problem. It's a hack, at some sizes the left margin is a bit off but so far this is the best solution I've found to this problem.
(defun adjust-left-margin-hook ()
(let ((new-margin (+ 1 text-scale-mode-amount)))
(setq left-margin-width (if (< new-margin 0) 0 new-margin))
(set-window-buffer nil (...
You could customize the variable linum-format to be a format string that begins with a space. The simplest would be (setq linum-format " %d") which sticks one space in front of the formatted digit. I tried it out and it looks slightly weird:
The other thing is that if you're on Emacs 26, there is a new line number mode display-line-numbers-mode which is "...
The following links linum wiki and stackoverflow similar issue help me to reach a solution with the following code :
(add-hook 'prog-mode-hook 'linum-mode)
(defvar my-linum-format-string "%3d")
(add-hook 'linum-before-numbering-hook 'my-linum-get-format-string)
(defun my-linum-get-format-string ()
(let* ((width (1+ (length (number-to-...