Emacs: Make Whitespaces Visible

By Xah Lee. Date: . Last updated: .

Alt+x whitespace-newline-mode to make newline visible.

Call whitespace-mode (in emacs 23 or later), to make all whitespaces visible.

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.

whitespace-mode renders {spaces, tabs, newlines} characters with a visible glyph. This feature is useful for working with “tab separated values” (TSV) that's commonly used format for importing/exporting address books or spreadsheets. It's also useful in whitespace-significant languages such as Python.

To use it, call:

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

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.

GlyphUnicode
Code Point
(Decimal)
Unicode 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 also: Unicode: ASCII Character Symbols ␀ ␤ ␠ ␣ ¶ ↩

Whitespace Topic

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

Font/Unicode Topic

  1. Emacs: Unicode Tutorial
  2. Emacs File Encoding FAQ
  3. Unicode Basics: What's Character Set, Character Encoding, UTF-8?
  4. Emacs: Xah Math Input Mode
  5. Emacs: Xah Unicode Browser Mode

  1. Best Unicode Fonts for Programer
  2. Emacs: Font Configuration
  3. Emacs: Proportional Font
  4. Emacs: Cycle Fonts by Command
  5. Emacs: Set Line Spacing
  6. Emacs: toggle-word-wrap
  7. Elisp: Unicode Representation in String
Like it? Buy Xah Emacs Tutorial. Thanks.