在Visual Studio代码中显示空白字符

eir*_*den 358 whitespace visual-studio-code vscode-settings

是否可以在Visual Studio代码中显示空格字符,如空格字符?

似乎没有settings.json它的选项(虽然它是Atom.io中的一个选项),我无法使用CSS显示空白字符.

rev*_*evo 540

VS Code 1.6.0和更高版本

下面aloisdg所述,editor.renderWhitespace现在是一个enum采取none,boundaryall.要查看所有空格:

"editor.renderWhitespace": "all", 
Run Code Online (Sandbox Code Playgroud)

在VS Code 1.6.0之前

在1.6.0之前,您必须设置editor.renderWhitespacetrue:

"editor.renderWhitespace": true
Run Code Online (Sandbox Code Playgroud)

  • 有没有办法只为选定的字符做这个,比如Sublime的``draw_white_space':"selection"`选项? (22认同)
  • @drzaus,``editor.renderWhitespace":"boundary"`将是行的开头和结尾,其中"deitor.renderWhitespace":"all"`将显示所有空格.@AlexanderGonchiy,我发现打开文件>首选项>用户设置(或工作区设置)并在默认设置文件夹中使用"查找"来查找我需要的内容很有用. (14认同)
  • @noio还没有,但它正在路上[github](https://github.com/Microsoft/vscode/issues/1477) (10认同)
  • 文件 -> 首选项 -> 设置。搜索“空白”。在“编辑器:渲染空白”下有一个下拉菜单可以选择您的新设置。(v1.13.2) (3认同)

Cod*_*ute 110

它也可以通过主菜单完成 View -> Render Whitespace.之间,我正在使用Visual Studio CodeView -> Render Whitespace

  • 我必须先将其关闭再打开才能工作(之前它已经打开) (57认同)
  • 在v 1.36.x中,`View-> Render Whitespace` (2认同)

inf*_*k01 60

对于那些愿意使用键盘快捷键切换空白字符的用户,可以在keybindings.json文件中添加自定义绑定(" 文件">"首选项">"键盘快捷键").


示例:

// Place your key bindings in this file to overwrite the defaults
[
    {
        "key": "ctrl+shift+i",
        "command": "editor.action.toggleRenderWhitespace"
    }
]
Run Code Online (Sandbox Code Playgroud)

在这里,我已经指定了Ctrl+ Shift+ 的组合i来切换不可见的字符,你当然可以选择另一种组合.

  • 我的Visual Studio默认使用`ctrl + e ctrl + s`.对于像这样的组合快捷方式,您需要在两个组合之间放置一个空格,而不是逗号. (2认同)

xgq*_*rms 48

在Visual Studio代码中显示空白字符

通过添加以下代码更改setting.json!

// Place your settings in this file to overwrite default and user settings.
{
    "editor.renderWhitespace": "all"
}
Run Code Online (Sandbox Code Playgroud)

像这样!
(PS:没有"真实"选项!即使它也有效.) 在此输入图像描述


Zac*_*k S 27

为了演示editor.renderWhitespace : true将对您的VSCode做的更改,我添加了此屏幕截图:
在此输入图像描述.

哪里Tab?Space.

  • PS 颜色模式不是更改的一部分(我有一个额外的插件) (2认同)

alo*_*ica 16

它不再是boolean了.他们换成了enum.:现在我们可以选择none,boundary并且,all.

// Controls how the editor should render whitespace characters,
// posibilties are 'none', 'boundary', and 'all'.
// The 'boundary' option does not render single spaces between words.
"editor.renderWhitespace": "none",
Run Code Online (Sandbox Code Playgroud)

你可以在GitHub上看到原始差异.

  • 也可以安装一个名为Trailing Spaces的扩展来仅显示尾随空格. (2认同)
  • 现在它还支持“尾随”和“选择”。另请参阅:https://github.com/microsoft/vscode/issues/163213 (2认同)

And*_*iko 13

  1. 打开用户首选项。键盘快捷键:CTR + SHIFT + P-> 首选项:打开用户设置;

  2. 在搜索字段中插入Whitespace,并选择所有参数 在此处输入图片说明

  • 此外,对于 VS Code 1.45(在 OSX 上),默认值为“选择”。 (2认同)

Moj*_*ini 7

所有平台(Windows/Linux/Mac):

它位于View -> Render Whitespace 下

?? 有时菜单项显示它当前处于活动状态,但您可以看到空白。您应该取消选中并再次检查以使其正常工作。这是一个已知的错误


关于 macOS 的注意事项?

在mac环境下,你可以在Help菜单下搜索任意菜单选项,就会打开你要找的确切菜单路径。例如,搜索的白色空间,结果如下:

演示


P.B*_*key 5

为了使diff显示空白,类似地将其git diff设置diffEditor.ignoreTrimWhitespace为false。 edit.renderWhitespace只是有一点帮助。

// Controls if the diff editor shows changes in leading or trailing whitespace as diffs
"diffEditor.ignoreTrimWhitespace": false,
Run Code Online (Sandbox Code Playgroud)

要更新设置,请转到

文件>首选项>用户设置

Mac用户注意:“首选项”菜单位于“代码而非文件”下。例如,代码>首选项>用户设置。

这将打开一个名为“默认设置”的文件。扩大面积//Editor。现在,您可以看到所有这些神秘editor.*设置的位置。在(CTRL + F)中搜索renderWhitespace。在我的盒子上,我有:

// Controls how the editor should render whitespace characters, posibilties are 'none', 'boundary', and 'all'. The 'boundary' option does not render single spaces between words.
"editor.renderWhitespace": "none",
Run Code Online (Sandbox Code Playgroud)

更令人困惑的是,左侧窗口“默认设置”不可编辑。您需要使用标题为“ settings.json” 的窗口覆盖它们。您可以将粘贴设置从“默认设置”复制到“ settings.json”:

// Place your settings in this file to overwrite default and user settings.
{
     "editor.renderWhitespace": "all",
     "diffEditor.ignoreTrimWhitespace": false
}
Run Code Online (Sandbox Code Playgroud)

我最终关掉了车renderWhitespace


Dra*_*hts 5

现在,使空白可见的选项在“视图”菜单上显示为一个选项,在Visual Studio Code版本1.15.1中显示为“切换渲染空白”。


Ste*_*lot 5

点击F1按钮,然后键入“ Toggle Render Whitespace”或您可以记住的部分:)

我使用的是vscode 1.22.2版,因此该功能可能早在2015年就不存在。


Mar*_*ark 5

v1.37更新:添加了仅在选定文本内呈现空白的选项。参见v1.37发行说明,渲染空白

editor.renderWhitespace设置现在支持一个selection选项。设置此选项后,空白将仅显示在选定的文本上:

"editor.renderWhitespace": "selection"
Run Code Online (Sandbox Code Playgroud)

"workbench.colorCustomizations": {    
  "editorWhitespace.foreground": "#fbff00"
}
Run Code Online (Sandbox Code Playgroud)

空白演示在选择中呈现