Last updated: Apr 6, 2024
Reading time·4 min
To render whitespace characters in VS Code:
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
When the Editor: Render Whitespace setting is set to all, all whitespace characters are displayed.
You can also set the setting to:
selection
- to only display the whitespace characters in the highlighted
text.trailing
- to only display the trailing whitespace characters.boundary
- displays whitespace characters at the beginning and end of lines
(not between words).Once the setting is set to all, all whitespace characters are shown.
You can also show the whitespace characters using the top menu:
Alt
to show the top menu on Windows and Linux.If you don't see the top menu on Windows or Linux, press the Alt
key to toggle
it.
You can also render whitespace characters using a settings.json
file:
settings.json
file in the .vscode
folder.Add the following code to the settings.json
file.
{ "editor.renderWhitespace": "all", "workbench.colorCustomizations": { "editorWhitespace.foreground": "#F4EA56" } }
Make sure the .vscode/settings.json
file is located in the root directory of
your project.
The following setting is used to render all whitespace characters.
{ "editor.renderWhitespace": "all", }
And, the following setting is used to set the color of the whitespace characters.
{ "workbench.colorCustomizations": { "editorWhitespace.foreground": "#F4EA56" } }
The setting is optional and can be set using the #RGB, #RGBA, #RRGGBB or #RRGGBBAA formats.
You can also show whitespace characters by updating your global settings.json file:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.Type user settings json
.
Click on Preferences: Open User Settings (JSON)
settings.json
file."editor.renderWhitespace": "all", "workbench.colorCustomizations": { "editorWhitespace.foreground": "#F4EA56" }
Make sure the properties are wrapped in an object if your settings.json
file
is empty.
{ "editor.renderWhitespace": "all", "workbench.colorCustomizations": { "editorWhitespace.foreground": "#F4EA56" } }
The workbench.colorCustomizations
property is optional and sets the color of
the whitespace characters.
If you already have the property set in your settings.json
file, you have to
simply add the "editorWhitespace.foreground": "#F4EA56"
line to the object.
Make sure you don't declare the workbench.colorCustomizations
object multiple
times in your settings.json
file.
You can also use a keyboard shortcut to toggle rendering the whitespace characters in your project.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.You will be prompted to press the desired key combination.
Once done, press Enter
to set the keyboard shortcut.
Now you can use the keybinding to show or hide the whitespace characters.
I've also written an article on how to remove the trailing spaces automatically in VS Code.
You can learn more about the related topics by checking out the following tutorials: