Home > Article > Development Tools > How vscode configures the go language development environment
Install Go development extension
Now we need to install the Go extension plug-in for our VS Code editor, let It supports Go language development.
Install Go language development tool kit
Press Ctrl Shift P on Windows platform and press Ctrl Shift P on Mac platform Command Shift P. At this time, an input box will pop up on the VS Code interface, as shown below:
Enter >go:install in this input box, and the following will automatically search for related information. command, we select the command Go:Install/Update Tools
and select it and press Enter to execute the command (or click the mouse with the Command)
Then click the "OK" button to install. The following input window will pop up:
VS Code will download and install the 16 tools listed above at this time. However, due to the domestic network environment, the installation will basically fail, as shown in the following FAILED:
Solution: Use git to download the source code and then install it
We can manually download the tool from github, (To perform this step, you need to have git installed on your computer)
Step one: Now create the golang.org/x directory under the src directory of your GOPATH
Step two: In the terminal/cmd, cd to the GOPATH/src/golang.org/x directory
Step 3: Execute the git clone https://github.com/golang/tools.git tools command
Step 4: Execute the git clone https://github.com/golang/lint.git command
Step 5: Press Ctrl/Command Shift P and execute the Go:Install/Update Tools command again, Select them all in the pop-up window and click OK. This time the installation will be SUCCESSED.
After following the above steps, the installation can be successful. At this time, when you create a Go file, you can use code prompts, code formatting and other tools normally.
Configuring automatic saving
Click Preferences->Settings. When you open the settings page, you can see the relevant configuration of automatic saving as shown in the figure. You can choose the automatic saving method according to your own preferences:
Configure code snippet shortcut keys
or Press Ctrl/Command Shift P, enter >snippets as shown below, select the command and execute it:
## Then click in the pop-up window Select the go option: You can briefly read the above comments, which introduce the main usage: where $0 represents the final position of the cursor. For example, I have created two shortcuts here. One is to enter pln and the fmt.Println() code will be inserted into the editor; enter plf and the fmt.Printf("") code will be inserted. After adding the above configuration, save it. Recommended related articles and tutorials:The above is the detailed content of How vscode configures the go language development environment. For more information, please follow other related articles on the PHP Chinese website!