Emacs: Make Whitespaces Visible

By Xah Lee. Date: . Last updated: .

whitespace-mode renders {spaces, tabs, newlines} characters with a visible glyph. (in emacs 23 or later)

There is also whitespace-newline-mode and global-whitespace-newline-mode. They only show newline chars.

emacs whitespace mode 2017 02 14
The default rendering of whitespace-mode. Different placement and mix of whitespaces are rendered with different colors. Also, long lines are colored dark purple.

Setting Up whitespace-mode

emacs whitespace mode clean 2017 02 14
A clean setup for whitespace-mode.

Download sample test file: whitespace_sample_file.txt

For a simple and clean whitespace mode setup, put the following in your emacs init.

(progn
 ;; Make whitespace-mode with very basic background coloring for whitespaces.
  ;; http://ergoemacs.org/emacs/whitespace-mode.html
  (setq whitespace-style (quote (face spaces tabs newline space-mark tab-mark newline-mark )))

  ;; Make whitespace-mode and whitespace-newline-mode use “¶” for end of line char and “▷” for tab.
  (setq whitespace-display-mappings
        ;; all numbers are unicode codepoint in decimal. e.g. (insert-char 182 1)
        '(
          (space-mark 32 [183] [46]) ; SPACE 32 「 」, 183 MIDDLE DOT 「·」, 46 FULL STOP 「.」
          (newline-mark 10 [182 10]) ; LINE FEED,
          (tab-mark 9 [9655 9] [92 9]) ; tab
          )))

In the above, the numbers are Unicode codepoint in decimal. Depending on your choice of font, some glyphs may not show up or correctly. If so, you can try the following glyphs.

[see ASCII Character Symbols ␀ ␣ ¶]

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy JavaScript in Depth

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


Emacs Tutorial

Quick Start

Manage Windows

File

Buffer

Dired

On Current File

Find Replace

Copy/Paste

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Things

Working with Brackets

Power Editing

Org Mode

HTML

Emacs Efficiency

Misc