4

Sometimes, I (in release) find this character. So, how can I highlight it in Visual Studio Code?

PS: I know about UTF-8 without a BOM, but to fix it, I need to open a page with the code in Notepad++ and change encoding. And I want to see this Unicode character in Visual Studio Code somehow highlighted, so I can see it (and delete it later).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

2 Answers2

8

How it works

  1. I add extension Gremlins

  2. and in C:\Users\tomnolane.vscode\extensions\nhoizey.gremlins-0.6.2\extension.js, add this code:

     const gremlins = [
       {
        ...
       },
       {
         char: 'feff',
         regex: /\ufeff+/g,
         width: 0,
         message: 'Zero Width No-Break Space',
         backgroundColor: 'rgba(255,127,80,.5)',
         overviewRulerColor: 'rgba(255,127,80,1)',
       },
       {
         char: '2060',
         regex: /\u2060+/g,
         width: 0,
         message: 'Word Joiner',
         backgroundColor: 'rgba(255,127,80,.5)',
         overviewRulerColor: 'rgba(255,127,80,1)',
       },
       {
         char: 'fffe',
         regex: /\ufffe+/g,
         width: 0,
         message: 'Not a Character',
         backgroundColor: 'rgba(255,127,80,.5)',
         overviewRulerColor: 'rgba(255,127,80,1)',
       },
     ]
    
  3. then, reload Visual Studio Code and it works!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

With the new setting: Editor > Unicode Highlight: Invisible Characters set to true or deriveFromWorkspaceTrust.

In file settings.json

"editor.unicodeHighlight.invisibleCharacters": true,

the Unicode character U+200B (zero-width space character) will be highlighted.

See more at How can I find Unicode characters that are not UTF-8 in Visual Studio Code?.

Mark
  • 143,421
  • 24
  • 428
  • 436
  • U+FEFF is not 'zero-width space'. U+FEFF is [ZERO WIDTH NO-BREAK SPACE](https://www.charset.org/utf-8/66). U+200B is [ZERO WIDTH SPACE](https://www.charset.org/utf-8/9). – Peter Mortensen Apr 25 '23 at 20:01