There are several ways to customize the display of the cursor. I happen to prefer highlighting the current line as a visual cue to keep my eye focused on where I’m working.

Before a few days ago, I had not realized there were so many packages to accomplish this, but let’s review a few.
highlight-current-line
I’ve used highlight-current-line for years. It’s a very adequate package. To enable, put highlight-current-line.el in your load-path and add the following to your emacs initialization:
(require 'highlight-current-line) (highlight-current-line-on t) ;; To customize the background color (set-face-background 'highlight-current-line-face "light yellow")
hl-line
To my surprise, I learned that GNU Emacs 21 introduced a built-in hl-line-mode. To enable it globally, add this to your emacs initialization:
(global-hl-line-mode 1) ;; To customize the background color (set-face-background 'hl-line "#330") ;; Emacs 22 Only ;(set-face-background 'highlight "#330") ;; Emacs 21 Only
(Note the difference between customizing the color in Emacs 21 and 22.)
highline
Highline was inspired by hl-line, highlight-current-line, and linemenu. It is supposedly the best option for the XEmacs contingent. To enable, put highline.el in your load-path and add the following to your emacs initialization:
(require 'highline) (highline-mode 1) ;; To customize the background color (set-face-background 'highline-face "#222")
Even More
Other packages such as hl-line+, col-highlight, and crosshairs have extra features such as idle-timers, line flashing, and column highlighting. I found most of these a little over-the-top, but if your personal preferences differ, give them a try.
Background Colors
I use a black emacs background and prefer a deep-dark gray like #111 for highlighting to keep things subtle.

When on a white background, I prefer a light yellow such as lemon chiffon or light goldenrod yellow. What colors do you like?

Conclusion
Up until this article, I used highlight-current-line, but I just switched to using the built-in hl-line. It’s now one less dependency I need to manage, and hl-line happens to work better in conjuction with visible bookmarks.
Bibliography
1 EmacsWiki, HighlightCurrentLine — libraries that highlight the current line of characters.
2 GNU Emacs Manual, Displaying the Cursor
3 EmacsWiki, HighlightCurrentColumn — libraries that highlight the current column of characters.
19 responses so far ↓
I’ve enabled the hl-line mode. Thanks!
I notice that when the current line is highlighted, all the other faces are dissabled. So, in a C file, the keywords are no longer bold etc.
Is there a way to keep all the other highlighting intact, and just shade the background slightly?
colours, It sounds like the foreground color for the
hl-line(orhighlight) face is set to something other thannil. To fix, try this:Thanks!
FYI, on my emacs 23, (set-face-background ‘hl-line “#222”) works, but only (set-face-foreground ‘highlight nil) works to preserve the color-theme colors. Weird.
(and you must do the above after loading the color theme
One question: if i use global-hl-line-mode, is it possible to turn it off for certain modes? M-x hl-line-mode doesn’t seem to turn it off.
sec, Using
hl-line, you can set a buffer-local variable to turn it off for certain modes or buffers. For example:This would turn off
hl-linefor all ruby buffers. You could also runM-x local-hl-line-mode-offto turn it off for a specific buffer.Alternatively, for
highlight-current-line, it supports a regexp to disable highlighting for certain buffers. Buffers whose buffer-name match the regular expression in the customizable variablehighlight-current-line-ignore-regexpdo not highlight.The
highlinepackage also has support for turning off highlighting in local buffers (M-x highline-off).Thanks, works perfectly. I don’t want hl-mode in Erc-Buffers, so i hooked it up for that. You don’t need the lambda in add-hook I think.
sec, Yes, you’re right. I cleaned up the hook above.
Hi & thanx for the tip, but I don’t manage to preserve my color-theme colors.
The 4 lines i’ve put in my .emacs :
The result : http://kraymer.free.fr/public/highlightline.tiff
I’m using Emacs 22.0.92.1 (Carbon Version 1.6.0)
KraYmer, Be sure to load your color-theme before setting the face colors for
hl-lineorhighlight. Some color-themes will reset the face colors forhighlightand hl-line can be affected by that.If anyone else is having trouble, you can double check your face values by running
M-x describe-face. It will prompt you for a face name. Run it once forhl-lineand again forhighlight. Make sure that the foreground colors for both are unspecified.The reason some people have seen issues with
highlightaffecting things in Emacs 22 or 23 is because thehl-lineface inherits fromhighlight.11 dude… » Blog Archive » zsh + screen + emacs ? 256 ?????????????? // May 29, 2007 at 2:25 pm
[...] ??????????????????Highlight the Current Line?????highlight-current-line.el??????????????? [...]
Thanks for this tip
13 EMSTONE Crew » Blog Archive » emacs ??? ?? ? // Dec 28, 2008 at 4:31 am
[...] ?? ???: http://www.emacsblog.org/2007/04/09/highlight-the-current-line [...]
Hi, a very good post, really thanks.
I have questions. First,
it doesnt work the GNU Emacs 21 built-in hl-line-mode in my xemacs i have seen that i have XEmacs 21.4 i have tried all that you said. I have also downloaded hl-line.el to try but it doesn´t work.
I have tried also the visible bookmark and they don´t work i have an error define-fringe-bitmap is void.
15 Highlight the Current Line | Best Eye Cream // Jun 8, 2009 at 2:40 am
[...] Highlight the Current Line Posted by root 2 hours 22 minutes ago (http://www.emacsblog.org) Some color themes will reset the face colors for highlight and hl line can be affected by that leave a comment powered by wordpress styled by cutline Discuss | Bury | News | Highlight the Current Line [...]
Thanks for the tip, works great!
Great post! How did I ever live without this?
Awesome, enabled it.
comment2, http://eyfnyersi.nazory.cz/page_976.html çíàêîìñòâà íîâîñèáèðñêîé îáëàñòè, 636947,
Leave a Comment