是否有可能显示空白字符,像空格字符,在Visual Studio代码?

在设置中似乎没有这个选项。json(虽然它是Atom.io中的一个选项),我还不能使用CSS显示空白字符。


当前回答

更新(2022年12月) 对于最新版本的VSCode,您可以执行视图->外观->渲染空白。

其他回答

***更新2020年8月发布***见https://github.com/microsoft/vscode/pull/104310

“编辑器。renderWhitespace": " trails " //添加选项

Add a new option ('trailing') to editor.renderWhitespace that renders only 
trailing whitespace (including lines with only whitespace).

***更新2020年2月发布***见https://github.com/microsoft/vscode/issues/90386

在v1.43中,默认值将像在v1.42中一样更改为从无选择。

"editor.renderWhitespace": "selection"  // default in v1.43

v1.37更新:增加了只在选定文本中呈现空白的选项。参见v1.37版本说明,渲染空白。

编辑器。renderWhitespace设置现在支持选择选项。使用此选项集,空格将只在选定的文本上显示:

"editor.renderWhitespace": "selection"

and

"workbench.colorCustomizations": {    
  "editorWhitespace.foreground": "#fbff00"
}


我想把这个建议作为旁注提出来。 如果你想修复所有的“尾随空白”警告,你的linter 扔给你。 你可以让VSCode自动从整个文件中删除空白 键盘和弦。 CTRL+K / X(默认)

我正在寻找显示空白,因为我的linter一直困扰我的空白警告。这就是我来这里的原因。

点击F1按钮,然后输入“Toggle Render Whitespace”或你能记住的部分:)

我使用的是vscode版本1.22.2,所以这可能是一个在2015年不存在的功能。

为了让diff显示空白类似于git的diff设置diffEditor。ignoreTrimWhitespace为false。编辑。renderWhitespace的帮助很小。

// Controls if the diff editor shows changes in leading or trailing whitespace as diffs
"diffEditor.ignoreTrimWhitespace": false,

若要更新设置,请转到

>首选项>用户设置 Mac用户注意:“首选项”菜单在“代码”而不是“文件”下面。为 例如,代码>首选项>用户设置。

这将打开一个名为“默认设置”的文件。展开//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",

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

// Place your settings in this file to overwrite default and user settings.
{
     "editor.renderWhitespace": "all",
     "diffEditor.ignoreTrimWhitespace": false
}

我最终关闭了renderWhitespace。

它不再是布尔值了。他们切换到enum。现在我们可以选择:无、有边界和全部。

// 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",

你可以在GitHub上看到最初的差异。