Why do I get ugly/bright tab indentation highlights?

Doom is highlighting my indentation strangely. What does this mean? How do I get rid of it?

image image

(left: with highlights, right: without)

Doom highlights non-standard indentation. i.e. Indentation that doesn’t match the indent style you’ve set for that file. Spaces are Doom’s default style for most languages (excluding languages where tabs are the norm, like Go).

There are a couple ways to address this:

  1. Fix your indentation! If it’s highlighted, you have tabs when you should have spaces (or spaces when you should be using tabs).

    Two easy commands for that:

    • M-x tabify
    • M-x untabify
  2. Change indent-tabs-mode (nil = spaces, t = tabs) in ~/.doom.d/config.el:

    ;; use tab indentation everywhere
    (setq-default indent-tabs-mode t)
        
    ;; or only in certain modes
    (setq-hook! 'sh-mode-hook indent-tabs-mode t) ; shell scripts
    (setq-hook! '(c-mode-hook c++-mode-hook) indent-tabs-mode t)  ; C/C++
    
  3. Use editorconfig to configure code style on a per-project basis. Enable Doom’s :tools editorconfig module for editorconfig integration with Emacs.

  4. Or trust in dtrt-indent; a plugin Doom uses to analyze and detect indentation when you open a file (that isn’t in a project with an editorconfig file). This isn’t foolproof, and won’t work for files that have no content in them, but it can help in one-off scenarios.