When editing text, I find it quite nice to highlight the current line, that is, the line where the cursor is, gets a different color. This can be easily done with emacs, by putting
global-hl-line-mode (more about
modes) and the following in your
.emacs:
(defface hl-line '((t (:background "Gray")))
"Face to use for `hl-line-face'." :group 'hl-line)
(setq hl-line-face 'hl-line)
(global-hl-line-mode t)
What this does:
- first, we define a special font ('face' in emacs-jargon) and we call it hl-line; there is a special format for that, which is discussed in detail in the ELisp Manual;
- second, we assign this 'face' to the hl-line-face-variable; this determines the face that will be used for highlighting;
- third, we turn the highlighting on for all modes.
That is all. Now, some notes to this:
- You can of course experiment with the font/face: you can change the foreground and background colors, make things bold or italic, bigger or smaller, etc. -- personally I like to keep things a bit subtle;
- In some emacs-versions, hl-line-mode may not be available; if you need to use your .emacs which such an emacs, the entry on using functions only if they are available might come handy.
4 comments:
Thanks, great tip!
FWIW, for color themes with black backgrounds (I'm using arjen), I like "Gray10" for my line highlighting.
This helps greatly the readability of wrapped lines. Fiddling with line highlights got to be a bit of a time sink when I discovered
M-x list-colors-display
Thanks for tip!
I like the way the command line in *shell* highlights. Thanks for the tip.
Is there a way to "enable hl-line-mode for all modes except specified modes"? For example I want it on everywhere except when term-mode is enabled?
Post a Comment