在对 Golang 的设置进行了一些麻烦之后,仅在选项卡上找到了解决方案,但是现在,在格式化我的代码后, VSCode 返回到以前的行为。
我希望我的标签为 4个空间,而不是标签字符。
这是我设置的一部分:
"editor.tabCompletion": true,
"editor.detectIndentation": false,
"editor.tabSize": 4,
// Insert spaces when pressing Tab.
"editor.insertSpaces": true,
"go.formatOnSave": false,
"[go]": {
"editor.detectIndentation": false,
"editor.tabSize": 4,
"editor.insertSpaces": true
},
"markdownlint.config": {
"default": true,
"MD033": false
}
按照链接查看图片,然后重新格式化
这是重新格式化后的图像
重新格式化前后我的状态栏保持不变
和我安装的扩展程序,以防万一这是一个扩展问题
谢谢你的帮助
最佳答案
我的解决方案:
我在macOS上工作,必须从终端安装gnu-sed: brew安装gnu-sed
安装Run On Save扩展。
编辑settings.json。我的设置:
{
"editor.renderWhitespace": "all",
"python.pythonPath": "/anaconda2/bin/python",
"[go]": {
"editor.insertSpaces": true,
"editor.tabSize": 4,
"editor.formatOnSave": true,
},
"runOnSave.statusMessageTimeout": 3000,
"runOnSave.commands": [
{
"match": ".*\\.go",
"notMatch": "",
"command": "gsed -i 's|\\t| |g' ${file}",
"runIn": "backend"
}
]
}
您可以在Linux上使用sed命令,而在Windows上使用类似的命令。
请注意gsed必须可用。 $ PATH应该被更新才能找到它。
另外,可以在“终端”中设置“runIn”属性,以确保一切正常。
关于go - Visual Studio代码:转到-重新格式化后,选项卡设置无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47654479/