GoLand implements automatic formatting of code


1. Using file watchers

Enter file watchers in the Golan – > Preferences – > search box – > select File watchers – > click the + sign in the lower left corner on the right – > select go FMT template – > pop up the setting box, default options – > click OK – > OK

After the setting is successful, your code will be automatically formatted when writing the go file. If it does not take effect, please restart


2. Using GoLand code submission tool

In the GIT submission tool provided by GoLand, click the submit button – > check go FMT – > in the pop-up page and submit again

Here, go FMT will be executed automatically before the code is submitted. The difference between this method and the above method is that the code will be formatted only when the code is submitted, and the code will not be forced to be formatted during the coding process


3. Formatting code with shortcut keys

The file watcher will force formatting during the encoding process, which some people will not adapt to,

When Git is submitted, it is formatted. Sometimes we want to see the format effect. It is too late. We can manually format the code and use it

Command + option + L. here is the L key. You don’t need to press shift

You can format the code anytime, anywhere

Here is a shortcut to the Mac



Supplement: the code FMT is automatically formatted when Golan is saved

GoLand idea can help us format code automatically when saving

Here is how GoLand is configured:


2、tools-file watchers

3. Add go FMT

4. Test write code (Ctrl + s), save and format the code

The above is my personal experience. I hope I can give you a reference, and I hope you can support developpaer. If you have any mistakes or don’t consider completely, please don’t hesitate to comment.

Recommended Today

SQL exercise 20 – Modeling & Reporting

This blog is used to review and sort out the common topic modeling architecture, analysis oriented architecture and integration topic reports in data warehouse. I have uploaded these reports to GitHub. If you are interested, you can have a lookAddress:https://github.com/nino-laiqiu/TiTanI recorded a relatively complete development process in my hexo blog deployed on GitHub. You can […]