In vim, we can use "set cursorline" in dotvim file to turn it on. Is there a way to do this in emacs?
In your .emacs, customize the face for hl-line-mode
, with something like:
(global-hl-line-mode 1)
(set-face-attribute hl-line-face nil :underline t)
hl-line-face
is a variable that stores the name of the face hl-line-mode
uses to show the current line. You can customize the :foreground
:background
and a bunch of other attributes to your liking. Check the docs here.
The global-hl-line-mode
turns on highlighting the current line in all buffers. If you just want it in some buffers, turn it on with M-x hl-line-mode.
There is a good blog post about this topic: M-x all-things-emacs
The following code (enter wit M-: or in ~/.emacs) uses the RGB code #222 as background color (if you are in 256-color mode!) and underlines the font on the current line. Unsetting the foreground color uses the default color, this e.g. preserves the C++ colours on the highlighted line.
(global-hl-line-mode 1)
(set-face-background 'highlight "#222")
(set-face-foreground 'highlight nil)
(set-face-underline-p 'highlight t)
You can check whether you need to change highlight
or (afaik older) hl-line
with M-x and:
describe-face <RET> highlight
describe-face <RET> hl-line
This command shows you all settings of the font face used for highlighting the current line. You should get an output like this:
Face: highlight (sample) (customize this face)
Documentation:
Basic face for highlighting.
Family: unspecified
Foundry: unspecified
Width: unspecified
Height: unspecified
Weight: unspecified
Slant: unspecified
Foreground: unspecified
Background: #222
Underline: t
Overline: unspecified
Strike-through: unspecified
Box: unspecified
Inverse: unspecified
Stipple: unspecified
Font: unspecified
Fontset: unspecified
Inherit: unspecified
I don't think there's an exact equivalent built in. You can use hl-line-mode to highlight the current line, and customising that mode lets you set the highlighting to be underlining rather than the default different background colour -- but the underline you get stops at the end of the text in the line, rather than continuing to the edge of the window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With