29

I am trying to figure out why VSCode sometimes decides to randomly insert "non-breaking spaces" U+00A0 instead of regular spaces, and how to stop this from happening?

This is a different type of space character which is causing issues, as seen in my previous question GitHub markdown not rendering and git detecting changes when no changes

This is happening to me on both Mac OS and Windows, and others have experienced this issue too. Although this question is about VSCode, this also happens on the online GitHub markdown editor.

How do I solve this problem?

Steps to reproduce

Edit a markdown .md file in VSCode for a while.

Put in lots of headings such as # my heading or ## my sub-heading.

If you have the markdown extension you can CTRL/CMD + SHIFT + P and Open preview to the side.

You should eventually notice that one of the headings doesn't render, and if you open the file in a hex editor such as HxD you'll notice that there is a non-breaking space instead of a regular space after the # character.

Possible causes

  • The backtick ` character on Windows can be combined with a letter on your keyboard for example a which results in à. Maybe the use of backticks is causing the space character to turn into a non-breaking space? However this wouldn't explain the problem on Mac OS, because backticks can't be combined with other characters.

4 Answers 4

33

I have this a lot too on Mac OS, but it turns out I am still holding the option key slightly (or perhaps shift on your keyboard) when typing the space after just having used the modifier key to type #

I've installed https://marketplace.visualstudio.com/items?itemName=viktorzetterstrom.non-breaking-space-highlighter&ssr=false#overview to spot my mistakes early.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks I'll try the extension
There's an extension called Fix Irregular Whitespace which replaces this particular character on save (as opposed to highlighting it).
When you say "option" did you mean "shift"? I normally hit shift-3 to type a #. This GitHub issue says that shift-space gives you a U+00A0: github.com/microsoft/vscode/issues/13239
I did mean option but should have mentioned that I'm using a GB keyboard.
An extension isn't needed anymore. Simply activate View -> Appearance -> Highlight Whitespace, see stackoverflow.com/a/41398464/4654246
|
4

I just spent quite a lot of time trying to figure out why a "mv foo bar" command I copy and pasted from VScode was returning command not found. Turned out the space in between mv and foo was a non-breaking space which I only determined by pasting it into a unicode text converter. I would really like to know why this is happening and if it's a setting I can disable. I am using Windows 10 so I don't think it's just a Mac issue.

4 Comments

I have also experienced the problem on Windows, so definitely not just a mac issue (although I haven't noticed it in a while).
I can confirm the same issue on Linux
Nope, it seems to be Zero Width Space U+200b which doesn't get detected by extension mentioned by @Dries
What a nightmare! I've suffered this from long time ago. Do you know who adds the non-break space? Is it VScode, maybe an extension? I've experienced this mainly with Markdown docs.
2

I have faced this trouble several times when copy/pasting code from Microsoft Skype or Microsoft OneNote. Both programs convert regular spaces into special Unicode spaces when pasting into it.

By the way, since version 1.63, Visual Studio Code automatically highlights these special spaces.

Comments

0

I ran into this too, but I'm sure I unwittingly inserted the non-breaking spaces using the spacebar alone. I found the hexdump plugin useful for diagnosing the problem. I still don't know how to avoid it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.