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 examplea
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.