VS Code Configuration Go language development environment
VS Code Configuration Go language development environment
Said in front of the words, Go language is the use UTF8 encoding, in theory, use any text editor can do Go language development. You can choose according to their preferences. Editor / IDE is no best only the most suitable.
Download and install
VS Code
Official Download: https://code.visualstudio.com/Download
Three major platforms are supported, according to their own computer platform to select the corresponding installation package.
Double-click the downloaded installation file, double-click to install.
Simplified Chinese is installed plug-ins
Click on the left menu bar last item 管理扩展
in 搜索框
the input chinese
, select the result list of the first item, click install
install.
After installation will prompt the bottom right corner 重启VS Code
, and then restart your VS Code to display Chinese friends! VSCode
The main interface description:
Go install extensions development
Now we want to install our VS Code Editor Go
extension, it supports the Go language development.
Change Theme Editor
Click the 首选项->颜色主题
pop-up window as follows:
Sublime Text recommend similar style theme Monokai
, bright style and theme Light(Visual Studio)
. The next demo is in Light(Visual Studio)
screenshots theme.
Installation Go Language Development Kit
Go here to provide language development when such code hints for us, code completion feature congruent.
Press the Windows platform Ctrl+Shift+P
, Mac platform by Command+Shift+P
this time VS Code input screen will pop up a box, as shown below:
We are in the input box >go:install
, the following will automatically search for related commands, we choose Go:Install/Update Tools
this command
Enter will select and execute the command (or use the mouse to click on the command)
Then click the "OK" button to install. Input window will pop up as follows:
VS Code will be downloaded and installed on the case listed in FIG tool 16, but the domestic network environment will appear substantially the installation fails, the following various FIG FAILED
:
There are two ways to solve this problem:
Method a: download the source code using git install
We can manually download the tool from the github, (premise need to perform this step on your computer git is already installed)
The first step: now own GOPATH
the src
created directory golang.org/x
directory
Step Two: In the 终端/cmd
middle cd
to GOPATH/src/golang.org/x
the directory
The third step: execute git clone https://github.com/golang/tools.git tools
command
Step Four: Execute git clone https://github.com/golang/lint.git
command
Step Five: Press Ctrl/Command+Shift+P
executed again Go:Install/Update Tools
command, in the pop-up window and click OK whole election, this time the installation will be SUCCESSED
up.
After the above steps can be installed successfully. Go this time to create a file, you can normally use code hints, code formatting tools such as a.
Method two: Download the executable file has been compiled
If the above steps fail or do not bother to perform step by step, you can download I've compiled executable file, copy to own a computer GOROOT/bin
directory. go-tools Baidu cloud download link , password: vjx2.
Note: in particular the need to give permission to copy these files executable under Mac.
Configuration is automatically saved
Click 首选项->设置
to open the Settings page you can see automatically saved configuration is shown, you can choose to automatically save the way according to their preferences:
Configuration code fragment shortcuts
Or by the Ctrl/Command+Shift+P
press of an input >snippets
, and performs selection command:
Then click on the pop-up window select go
the option: then pop up the following page:
We can simply look at the note above, describes the main usage:
“这里放个名字”:{
"prefix": "这个是快捷键",
"body": "这里是按快捷键插入的代码片段",
"description": "这里放提示信息的描述"
}
Wherein $0
represents the final position of the cursor aside. For example, I've created two shortcuts, one input pln
will be inserted in the editor fmt.Println()
codes; input plf
, it will insert fmt.Printf("")
the code.
{
"println":{
"prefix": "pln",
"body":"fmt.Println($0)",
"description": "println"
},
"printf":{
"prefix": "plf",
"body": "fmt.Printf(\"$0\")",
"description": "printf"
}
}
After adding the above configuration, save. We go to open a file, test results
To be continued ...