如何在Goland中为所有项目默认启用指定文件监视器?
Hey there! I totally get the annoyance of having to set up the same goimports file watcher for every single new GoLand project—let’s sort this out so you never have to do that manual setup again.
Here’s the step-by-step to set it as a default for all new projects:
- Open GoLand’s global default settings:
- If you’re in an existing project, go to
File > New Projects Setup > Settings for New Projects - If you’re on the welcome screen, click
Configure > Settings for New Projects
- If you’re in an existing project, go to
- In the settings window, navigate to
Tools > File Watchers - Click the + button in the top-right corner to add a new watcher, then select
goimportsfrom the list (if it’s not there, you can chooseCustomand set it up manually) - Configure the watcher details to match your needs (here’s the standard setup that works for most folks):
- Program: Make sure this points to your installed
goimportsbinary. If GoLand doesn’t auto-detect it, you can manually set the path (e.g.,$GOPATH/bin/goimportsor the full path like/Users/yourname/go/bin/goimports) - Arguments: Use
-w $FilePath$(this tellsgoimportsto write changes directly to the file) - Working directory: Set to
$FileDir$ - Output paths to refresh: Enter
$FilePath$ - Don’t forget to check the box for Auto-save edited files to trigger the watcher if you want it to run automatically when you change a file
- Program: Make sure this points to your installed
- Click Apply then OK to save these default settings
From now on, every new project you create in GoLand will have the goimports file watcher enabled right out the gate.
Quick note for existing projects:
If you already have projects that need this watcher, you can export the configuration from one project (File > Export Settings, select File Watchers) and import it into others (File > Import Settings). Alternatively, if you use GoLand’s Settings Repository feature, you can sync your file watcher settings across all your projects automatically.
Also, double-check that goimports is installed on your system—if not, run this command in your terminal:
go install golang.org/x/tools/cmd/goimports@latest
内容的提问来源于stack exchange,提问作者Duncan Jones

