Reprinted fromwww.liwenzhou.com/posts/Go/00_go_i…
Vs Code configuring go language development environment
| Golang
Vs code is an open source editor of Microsoft, and the plug-in system is very rich. This paper introduces how to use vs code to build a go language development environment.
Due to the update iteration of go language and related editing tools, this article has been updated on March 25, 2020, which may be different from the video. Please refer to the updated article.
Vs Code configuring go language development environment
As mentioned above, the go language is encoded by utf8. Theoretically, any text editor can be used for go language development. You can choose according to your preferences. The editor / IDE has no best, only the best.
Download and install
VS Code
Official download address:code.visualstudio.com/Download
All three mainstream platforms support it. Please select the corresponding installation package according to your computer platform.Double click the downloaded installation file, and then double-click the installation.
Install Chinese Simplified plug-in
Click the last item in the menu bar on the leftManagement extension
, inSearch box
Medium inputchinese
, select the first item in the result list and clickinstall
Installation.
After installation, a prompt will appear in the lower right cornerRestart vs Code
, after restarting, your vs code will be displayed in Chinese!VSCode
Introduction to main interface:
Install go development extension
Now we are going to install for our vs code editorGo
Extension to support go language development.
Change editor theme
Click in turnSettings - > color theme
,The following window will pop up:
You can choose the corresponding theme according to your preferences.
Install go language development kit
During the development of go language, you will provide us with functions such as code prompt and automatic code completion.
Please set before thisGOPROXY
, open the terminal and execute the following commands:
go env -w GOPROXY=https://goproxy.cn,direct
Windows platform pressCtrl+Shift+P
, for Mac platformsCommand+Shift+P
At this time, an input box will pop up in the vs code interface, as shown in the following figure:
We enter in this input box>go:install
, the following will automatically search for relevant commands. We chooseGo:Install/Update Tools
Select this command according to the figure below and press enter to execute the command (or click the command with the mouse)Select all in the pop-up window and click “OK” to install.
Then the following window will pop up to start installing the tool:
Drink water and wait until all tools are installed successfully, as shown in the figure below:
Configure vscode to enable automatic saving
Click as shown in the figure belowFile - > Preferences - > Settings
,Open the settings page to see the relevant configurations automatically saved, as shown in the figure below. You can choose the automatic saving method according to your preferences:
Configure snippet shortcuts
Or pressCtrl/Command+Shift+P
, enter as shown in the figure below>snippets
, select the command and execute:
Then click Select in the pop-up windowgo
Options:Then the following page pops up:
You can take a brief look at the notes above to introduce the main usage:
"Put a name here":{
"Prefix": "this is a shortcut key",
"Body": "here is the code fragment inserted by pressing the shortcut key",
"Description": "here is a description of the prompt information"
}
among$0
Indicates the position of the final cursor. For example, I created two shortcuts here. One is inputpln
Will be inserted in the editorfmt.Println()
code; inputplf
, it will be insertedfmt.Printf("")
code.
{
"println":{
"prefix": "pln",
"body":"fmt.Println($0)",
"description": "println"
},
"printf":{
"prefix": "plf",
"body": "fmt.Printf(\"$0\")",
"description": "printf"
}
}
Paste the above code into the configuration file as shown in the figure below, save and close the configuration file.After adding the above configuration, save. Let’s open a go file and test the effect:
This work adoptsCC agreement, reprint must indicate the author and the link to this article