this post was submitted on 29 May 2024
10 points (100.0% liked)

Emacs

2192 readers
1 users here now

Our infinitely powerful editor.

founded 4 years ago
MODERATORS
 

In my pursuit to migrate from Vim to Emacs, I have stumbled on yet another roadblock.

When working with files that contain special whitespace characters, Vim/Neovim would automatically highlight these. This saved me a lot of time during debugging or data analysis, and is a functionality that I struggled to get to work on more modern IDEs.

However, this does not work out-of-the-box neither on vanilla Emacs nor Doom Emacs. I am unable to find any working solutions online. I assumed whitespace-mode would have handled this, but it is not the case.

It would be really helpful if the community here can help solve my problem as I deal with such characters on a daily basis. Until then, I have to pause my pursuit and stick with the trusty Neovim.

U+200B in Neovim

Notice Neovim highlighting the character as <200B>.

U+200B in Doom Emacs

Notice the think cursor between "hello" and "world".


Thanks to the suggestion by @[email protected], glyphless-display-mode allows me to view the characters. But it still doesn't play well with vim motions on Emacs.

Here is a demonstration, and below are the keystrokes.

  1. C-v to enable VISUAL-BLOCK mode.
  2. 9j to select all 9 occurrences.
  3. d to delete the selection.

The above vim-motion works on Neovim but not on Emacs with evil-mode.

If anyone wants to try out here is the text I am playing with:

hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 5 months ago* (last edited 5 months ago) (1 children)

Thanks. This helped me highlight the characters. But it still doesn't play well with vim motions on Emacs.

Here is a demonstration, and below are the keystrokes.

  1. C-v to enable VISUAL-BLOCK mode.
  2. 9j to select all 9 occurrences.
  3. d to delete the selection.

The above vim-motion works on Neovim but not on Emacs with evil-mode.

If anyone wants to try out here is the text I am playing with:

hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
hello ​ world
[–] [email protected] 2 points 5 months ago* (last edited 5 months ago) (1 children)

I don't know why the motion didn't work in Evil mode, but if the goal is deleting all invisible Unicode characters, I'd write a command like this:

(defun my/delete-invisibles-in-region (start end)
  "Delete invisible characters in the region specified with START and END."
  (interactive "r")
  (save-excursion
    (replace-regexp "\u200B\\|\u200C" "" nil start end))
    ;; (query-replace-regexp "\u200B\\|\u200C" "" nil start end))
  (deactivate-mark))
[–] [email protected] 1 points 5 months ago

Thanks again! I already have shell scripts to take care of such characters for me, which operate on entire files. Having a function like this would help for certain regions of a file. :-)

However, it does bug me a bit that some vim motions do not work exactly as intended. Going in, I knew evil-mode would have some gaps. But I assumed those would be some esoteric operations, and not something that I use daily.