2016-04-21 21:49
采纳率: 0%
浏览 123

在Sublime Text中保存运行goimports吗?

In Sublime Text 3, with plugins GoSublime and GoImports installed.

I'm having trouble having goimports run on my file automatically everytime I save.

Here's what I tried :

My GoSublime settings are set to :

    "env": {"GOPATH": "/home/nicolas/.go", "PATH": "$GOPATH/bin:$PATH" },
    //"fmt_cmd": ["goimports"]

When I save with these settings, the code gets formatted but imports are not added. Nothing surprising so far.

If I hit ctrl+shift+P then GoImports, imports get added as expected.

Now my problem is, when I uncomment that previous line to have these settings :

    "env": {"GOPATH": "/home/nicolas/.go", "PATH": "$GOPATH/bin:$PATH" },
    "fmt_cmd": ["goimports"]

Not only does it not add the imports, but no other formatting gets done anymore.

Any idea where I went wrong ?

I'm using Linux (Ubuntu).

图片转代码服务由CSDN问答提供 功能建议

在Sublime Text 3中,带有插件 GoSublime GoImports

我在每次保存时都无法自动在文件上运行 goimports

这就是我的问题 尝试过:


“ env”:{“ GOPATH”:“ / home /  nicolas / .go“,” PATH“:” $ GOPATH / bin:$ PATH“},
 //” fmt_cmd“:[” goimports“] 
 \  n 


如果我按ctrl + shift + P然后转到GoImports,则导入将按预期方式添加。

现在我的问题是,当 我取消注释前一行具有以下设置:

“ env”:{“ GOPATH”:“ /home/nicolas/.go”,“ PATH”:  “ $ GOPATH / bin:$ PATH”},
“ fmt_cmd”:[“ goimports”] 

不仅不添加导入 ,但其他格式都无法完成。



  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • duanjiao4763 2016-04-22 12:34
    1. Make sure $GOPATH/bin is in your $PATH (Windows: %GOPATH%\bin goes in your %PATH%).
    2. Run go get -u (you may have to install mercurial).
    3. Install Sublime Text and GoSublime (or make sure you’ve got the latest update if it’s already installed).
    4. Open the gosublime user config/preference file (Mac: ⌘. ⌘5 Windows: Ctrl+. Ctrl+5). Make sure you keep the command button down for the whole shortcut sequence.
    5. Make it look like this: {"fmt_cmd": ["goimports"]}


    解决 无用
    打赏 举报

相关推荐 更多相似问题