I have global-hl-line-mode setup in my init file:

(use-package hl-line
  :init (global-hl-line-mode 1))

Is it possible to disable it when I am in eshell and ansi-term? I tried adding a hook like this:

(add-hook 'eshell-mode-hook (hl-line-mode -1))

But it didn't work.


global-hl-line-mode sets variable global-hl-line-mode to t. The global mode is separate from the non-global (hl-line-mode).

The following will disable it in the selected mode:

(add-hook 'eshell-mode-hook (lambda ()
                                    (setq-local global-hl-line-mode
(add-hook 'term-mode-hook (lambda ()
                                    (setq-local global-hl-line-mode

The documentation indicates that setting it directly does not take effect, however when testing it it does remove the highlighting while in the *Eshell* buffer.

  • Works for eshell, thank you. Now I need something for ansi-term. – Manuel Uberti Mar 2 '15 at 19:30
  • 1
    Try term-mode-hook. – glucas Mar 2 '15 at 19:33

This works for ansi-term if you're using emacs 24.3+:

(add-hook 'term-mode-hook (lambda ()
                            (setq-local global-hl-line-mode

Thanks to Jonathan and glucas.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.