in my init.el file I have the following:

(global-linum-mode 1)
(add-hook 'term-mode-hook (lambda () (linum-mode))) 

However, when I enter ansi-term-mode linum mode is still on.

I have also tried

(add-hook 'ansi-term-mode-hook (lambda () (linum-mode))) 


(add-hook 'term-mode-hook (lambda () (linum-mode nil))) 

Does anyone have any idea how to turn off linum mode for ansi-term-mode only?

  • Did you try (linum-mode -1) ?
    – YoungFrog
    Oct 13, 2015 at 21:38
  • @YoungFrog yes to no avail.
    – Startec
    Oct 14, 2015 at 3:31
  • 1
    @Startec Just to be clear, you need to have (global-linum-mode 1) (add-hook 'term-mode-hook (lambda () (linum-mode -1))), then restart emacs to see the effect. Note the -1. Jan 11, 2016 at 16:02
  • This question gets asked over and over, with the description and title being about the specific mode. Someone (TM) please edit this to replace it by a (Community) generic question that is posed as is the SO duplicate automatically disable a global minor mode for a specific major mode.
    – Drew
    Nov 24, 2017 at 18:15

2 Answers 2


Refer to the duplicate question on StackOverflow:

automatically disable a global minor mode for a specific major mode

This was converted to a comment when it's a perfectly sensible answer (seeing as how we can't close for duplication across SE sites), so this text is just to prevent that from happening...


You can also do something like this:

(add-hook 'after-change-major-mode-hook
          '(lambda ()
              (if (-contains?
               0 1)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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