Emacs: Make Whitespaces Visible

By Xah Lee. Date: . Last updated: .

Here's how to make whitespaces visible {spaces, tabs, newlines}. (in emacs 23 (released 2010-05) or later)

Alt+x whitespace-mode
Make whilespace visible. Toggle on/off, for current file.
Alt+x global-whitespace-mode
Do it in every buffer.
Alt+x whitespace-newline-mode
Make just newline character visible.
Alt+x global-whitespace-newline-mode
Do it in every buffer.
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

You can configure whitespace mode to use a simple color scheme.

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://xahlee.info/emacs/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.

charcodepoint (decimal)name
·183MIDDLE DOT
182PILCROW SIGN
8629DOWNWARDS ARROW WITH CORNER LEFTWARDS
8617LEFTWARDS ARROW WITH HOOK
9166RETURN SYMBOL
9655WHITE RIGHT POINTING TRIANGLE
9654BLACK RIGHT-POINTING TRIANGLE
8594RIGHTWARDS ARROW
8614RIGHTWARDS ARROW FROM BAR
8677RIGHTWARDS ARROW TO BAR
8680RIGHTWARDS WHITE ARROW

[see ASCII Character Symbols ␀ ␣ ¶]

Emacs, Tab, Indentation, Whitespace


Emacs Tutorial

Quick Start

Font

Split Window

File

Buffer

Copy/Paste

Find Replace

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Special File

Editing Brackets

Org Mode

HTML

Emacs Efficiency

Misc