Weekly Emacs tip #10: Highlighting the current line with global-hl-line-mode
By default, the point (the cursor in Emacs-speak) is shown as a flashing block. And for years that was what I used. The flashing was enough for me to locate the cursor.
Back in July of last year, however, I started to look for something that showed the cursor location more clearly. I don’t exactly remember what triggered it, but it could be that I currently use a rather narrow symbol for the point. I also tend to split my Emacs frame (i.e. the Emacs window for normal people) into several windows side by side, which means it’s not immediately clear which window is the active one, with the “live” cursor.
Of course, Emacs has a minor mode that can solve this: enabling the built-in hl-line-mode
highlights the whole line containing the point. And if you switch to another window in your Emacs frame, the highlighted line “jumps” with you. This makes it very obvious where your active cursor is, as shown in the following screenshot.

Figure 1: Screenshot with the hl-line shown on the second line of the second paragraph.
To activate hl-line-mode
for all buffers, set the global-hl-line-mode
variable to t
. I do this by setting it in the :custom
section of my (use-package emacs)
block. In short (my actual :custom
section is much larger):
(use-package emacs :custom ;; Enable global highlight line mode so we can immediately see on ;; which line the cursor/point is (global-hl-line-mode t) )
No Comments