Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在保存时设置vscode格式golang code?_Go_Visual Studio Code - Fatal编程技术网

如何在保存时设置vscode格式golang code?

如何在保存时设置vscode格式golang code?,go,visual-studio-code,Go,Visual Studio Code,我正在使用vscode和Go扩展来编辑golang源代码。每次我想格式化代码时,我都必须在linux上按Ctrl-Shift-I,Windows上按Shift-Alt-F,或Ctrl-Shift-p并键入format。是否可以在保存时设置格式,也就是说,当我按ctrl-s键时,它会使用go.fmt(或类似的东西)自动格式化代码。您应该安装此插件:。其中一个选项是在保存时设置“自动格式”:go.formatOnSave:false。它使用Golang工具进行格式设置。从我的可视代码版本中,我无法使

我正在使用
vscode
Go
扩展来编辑
golang
源代码。每次我想格式化代码时,我都必须在
linux
上按
Ctrl-Shift-I
Windows
上按
Shift-Alt-F
,或
Ctrl-Shift-p
并键入
format
。是否可以在保存时设置格式,也就是说,当我按ctrl-s键时,它会使用go.fmt(或类似的东西)自动格式化代码。

您应该安装此插件:。其中一个选项是在保存时设置“自动格式”:
go.formatOnSave:false
。它使用Golang工具进行格式设置。

从我的可视代码版本中,我无法使用config go.formatOnSave:false

然后我可以在如下设置中关闭它们:

  • 生成(使用go.buildOnSave设置关闭)
  • Lint(使用go.lintOnSave设置关闭)
  • Vet(使用go.vetOnSave设置关闭)
  • 格式化(通过在设置中添加以下内容来关闭):

非常感谢。实际上我正在使用这个插件,但在问这个问题之前,我没有找到要设置的选项“go.formatOnSave”:true`成功了。我认为默认设置应该是
true
而不是
false
。另一件事是将“go.formatTool”从“go fmt”更改为“goimports”(并安装goimports)。让它管理您的导入非常方便(尽管使用时要小心,请仔细检查它是否导入了正确的内容)。
"[go]": {
    "editor.formatOnSave": false 
}