Visual studio golang environment configuration



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 CodeOfficial download

All three mainstream platforms support it. Please select the corresponding installation package according to your computer platform.Visual studio golang environment configurationDouble 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 boxMedium inputchinese, select the first item in the result list and clickinstallInstallation.

After installation, a prompt will appear in the lower right cornerRestart vs Code, after restarting, your vs code will be displayed in Chinese!Visual studio golang environment configurationVSCodeIntroduction to main interface:Visual studio golang environment configuration

Install go development extension

Now we are going to install for our vs code editorGoExtension to support go language development.Visual studio golang environment configuration

Change editor theme

Click in turnSettings - > color themeVisual studio golang environment configurationThe following window will pop up:Visual studio golang environment configurationYou 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=,direct

Windows platform pressCtrl+Shift+P, for Mac platformsCommand+Shift+PAt this time, an input box will pop up in the vs code interface, as shown in the following figure:Visual studio golang environment configuration

We enter in this input box>go:install, the following will automatically search for relevant commands. We chooseGo:Install/Update ToolsSelect this command according to the figure below and press enter to execute the command (or click the command with the mouse)Visual studio golang environment configurationSelect all in the pop-up window and click “OK” to install.Visual studio golang environment configuration

Then the following window will pop up to start installing the tool:Visual studio golang environment configuration

Drink water and wait until all tools are installed successfully, as shown in the figure below:Visual studio golang environment configuration

Configure vscode to enable automatic saving

Click as shown in the figure belowFile - > Preferences - > SettingsVisual studio golang environment configurationOpen 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:Visual studio golang environment configuration

Configure snippet shortcuts

Or pressCtrl/Command+Shift+P, enter as shown in the figure below>snippets, select the command and execute:Visual studio golang environment configuration

Then click Select in the pop-up windowgoOptions:Visual studio golang environment configurationThen the following page pops up:Visual studio golang environment configuration

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$0Indicates the position of the final cursor. For example, I created two shortcuts here. One is inputplnWill be inserted in the editorfmt.Println()code; inputplf, it will be insertedfmt.Printf("")code.

        "prefix": "pln",
        "description": "println"
        "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.Visual studio golang environment configurationAfter adding the above configuration, save. Let’s open a go file and test the effect:Visual studio golang environment configuration

This work adoptsCC agreement, reprint must indicate the author and the link to this article

If you are strong, you will be strong. If you are too strong, you can say otherwise