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.

 ;; 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 ␀ ␣ ¶]

Whitespace Topic

  1. Clean Empty Lines
  2. Delete Trailing Whitespace
  3. Delete Whitespace around Cursor
  4. Tabs, Space, Indentation Setup
  5. Make Whitespaces Visible
  6. Newline Representation ^M ^J ^L
  7. Batch Convert Line Ending in Dired

Unicode Topic

  1. Unicode Basics
  2. Unicode Tutorial
  3. Emacs File Encoding FAQ
  4. Best Unicode Fonts for Programer
  5. Elisp: Unicode Representation in String
  6. Xah Math Input Mode
  7. Xah Unicode Browser Mode

Font Topic

  1. Font Setup
  2. Proportional Font
  3. Cycle Fonts by Command
  4. Set Line Spacing

Rectangle Edit Topic

  1. Edit Column Text, Rectangle Commands
  2. Insert Alphabets A to Z
  3. Copy Rectangle Region to kill-ring
  4. Align Text
  5. picture-mode, ASCII Diagram
  6. Make Whitespaces Visible

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp