Elisp: Replace Invisible Unicode Chars

By Xah Lee. Date: . Last updated: .

Here's a command that replaces annoying invisible characters.

For example,

They happen when copying text from Twitter etc sites.

(defun xah-replace-invisible-char ()
  "Query replace some invisible Unicode chars.
The chars to be searched are:
 ZERO WIDTH NO-BREAK SPACE (65279, #xfeff)
 RIGHT-TO-LEFT MARK (8207, #x200f)
 RIGHT-TO-LEFT OVERRIDE (8238, #x202e)
 LEFT-TO-RIGHT MARK ‎(8206, #x200e)

Search begins at cursor position. (respects `narrow-to-region')

URL `http://ergoemacs.org/emacs/elisp_unicode_replace_invisible_chars.html'
Version 2018-03-05"
  (query-replace-regexp "\u200f\\|\u202e\\|\ufeff\\|\u200e\\|\ufffc" ""))

See also: Emacs: Unicode Tutorial

Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

Patreon me $5. Ask me question on patreon