Reputation: 5958
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
`
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.Upvotes: 27
Views: 15186
Reputation: 1345
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.
Upvotes: 2
Reputation: 436
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.
Upvotes: 32
Reputation: 1180
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.
Upvotes: 0
Reputation: 133
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.
Upvotes: 3