1

I have the following line turning hl-line-mode on globally in my init file:

(global-hl-line-mode)

Most of the time, that's how I like it. But sometimes I want to turn it off. I'd hoped that I could somehow override the global setting with a buffer-local one, by running hl-line-mode with a negative prefix argument. This does turn off the highlight for about a second, then it just comes back. I can, of course, disable global-hl-line-mode instead, but is there a way to do a buffer or window local override of this setting?

Update Kudos to @lawlist for the necessary mechanics. I bound this up in a little function and am quite happy with it.

(defun ivan/local-toggle-hl-line ()
  "Toggle line highlighting in current buffer"
  (interactive)
  (setq-local global-hl-line-mode
              (null global-hl-line-mode)))

Dedicating it to the same keybinding that iTerm2 uses for the same sort of thing ⌥⌘;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.