Highlighting and replacing non-printable Unicode characters in Emacs

I have a UTF-8 file containing some Unicode characters, such as LEFT-TO-RIGHT OVERRIDE (U + 202D), which I want to remove from the file. In Emacs, they are hidden by default (what should be the correct behavior?). How can I make such "exotic" Unicode characters visible (without changing the display of "regular" Unicode characters such as German umlauts)? And how to replace them after (for example, replace-string . CX 8 Ret does not work for isearch / replace-string ).

In Vim, it’s pretty easy: these characters are displayed with the default hexadecimal representation (is this an error or is there no function?), And you can easily delete them with :%s/\%u202d//g , for example. Should this be possible with Emacs?

+7
source share
2 answers

You can do Mx find-file-literally , then you will see these characters.

Then you can remove them using regular string-replace

+9
source

How about this:

Place the character U + 202d that you want to combine at the top of the ring by typing M-: (kill-new "\u202d") . You can then output this string to various search commands using Cy (e.g., query-replace ) or My (e.g., isearch-forward ).

(Edited to add :)

You can also just invoke commands non-interactively, which does not cause keyboard input problems like interactive calls. For example, enter M-: and then:

 (replace-string "\u202d" "") 

This is somewhat similar to your version of Vim. One of the differences is that it only performs replacements from the cursor position at the bottom of the file (or narrowed area), so you will need to go to the beginning of the file (or narrowed area) before running the command to replace all matches.

+4
source

All Articles