This is a creation in Article, where the information may have evolved or changed.
As a vimer, the Vim editor is still my first choice in everyday coding. This is true when you used the C language as the primary language, and now it is the main language for go. However, the recent discovery of the use of Vim on the Mac when writing the Go Code, vim, the occasional "convulsions": There are some "screen characters are tampered with" problem, such as the following image of "Func" became "FKNC":
Although the display will be corrected automatically after a period of time, this "tampering" will cause you to "illusion". You will think: Is it true that I have "func" written "Fknc"? Over time, this flaw will affect your coding efficiency. As to why this problem arises, the initial suspicion may be that some of the performance issues caused by VIM loading more plug-ins, I have not found this problem (the same. VIMRC configuration) on desktops with Ubuntu 16.04 installed.
So, I am going to find an auxiliary editor, used in the above problem to start "disgust" vim sometime, switch, calm mood ^0^. I fancy Microsoft Open source Visual Studio Code, abbreviated as: Vscode.
I. The origins of Visual Studio with Microsoft
Microsoft is a professional and very serious IDE. University at that time to learn C, dislike Turbo C is too humble, basically in the D version of Visual Studio 6.0 to complete a variety of jobs and small program production. Later, in 2001, Microsoft released the. NET strategy, released the C # language, and published the Visual Studio. NET IDE. I guess I was the first in the country to use the Visual Studio.NET IDE, then the Microsoft Club in the campus free to send vs.net Beta CD, I got a copy, and the first time to experience the vs.net. Visual Studio. NET is vastly different from the previous vs 6.0, powerful, and the interface has been redesigned to support Microsoft's various languages, including C #, C + + (including managed C + +), VB, ASP., and after a year after the release of the official version, gradually in the desktop application development to become the Overlord, the time of the IDE in the field of the rival Borland company completely defeated. But Visual Studio has also become more bulky and bloated, and installing a VS, without a few g-space, is not possible. Think of that time machine configuration, run a vs.net is really heart has not enough.
After work, go to the service-side programming area, get acquainted with UNIX, Linux and Vim, GCC, and never touch the visual Studio. As the working OS also switches from Windows to Ubuntu, the basic is insulated from vs. Then, as the Java language became the protagonist of enterprise applications, the advent of the web era, and the rise of Open source Ides (such as Eclipse), Microsoft's Visual Studio was no longer so dazzling, or people's attention to the IDE was not as strong as the time when the GUI program was developed. But given the sheer size of Microsoft's own product system, vs always has a niche in the market.
In recent years, a number of cross-platform, lightweight, plug-in structure, support IntelliSense, freely customizable text editor, such as: Sublime text, Atom, and so on, so that developers can not help. These editors are not located in the IDE, but do not lose to the IDE a lot, especially in the support of coding, debugging these links, they can be compared with professional ides, but the resource consumption is like visual Studio, eclipse, such as the chatty of the IDE can not match. and visual Studio code is one of Microsoft's most recent corporate strategies: embracing all developers (not just Windows).
Second, Vscode installation
Vscode was released at the build conference in April 2015. After the release, quickly get the developer response, we generally reflect: Vscode performance good, attention to detail, good experience, although at that time Vscode plug-ins are not too rich. After more than a year, Vscode has evolved to 1.8. Version 1 (as of the end of December 2016), supporting the development of all major programming languages, the supporting plug-ins are also very rich. Vscode installation is very simple, this is always the strength of Microsoft, you can download on its official site to the platform of the installation package (Linux platform also has. DEB/.RPM two package formats are available and available in 32bit and 64bit two versions). Install after download.
1. Vscode Configuration and data storage path
Vscode after installation, it is generally not necessary to care about the location of its configuration and data storage paths. But as a developer with some geek spirit, it is meaningful to figure out the ins and outs of the installation and configuration.
On the Mac:
Vscode store running data and configuration files in the directory under: ~/library/application Support/code:
~ / Library / Application Support / Code] $ ls
Backups / CachedData / Cookies-journal Local Storage / User /
Cache / Cookies GPUCache / Preferences storage.json
$ ls User
keybindings.json locale.json settings.json snippets / workspaceStorage /
In Ubuntu:
The directory where VSCode stores running data and configuration files is under ~ / .config / Code:
~ / .config / Code $ ls
Backups Cache CachedData Cookies Cookies-journal GPUCache Local Storage storage.json User
As for the Windows platform, please explore by yourself ^ _ ^.
2. Starting method
VSCode has two startup methods: desktop startup and command line startup. Needless to say, desktop startup. An example of command line startup is as follows:
$ code main.go
The code command will open a VSCode window and load the file content in the command parameters, here is main.go.
3. Configuration of VSCode
Generally speaking, VSCode is ready to use. But in order to give full play to the power of VSCode, we must configure it. There are dozens or hundreds of VSCode configurations, which cannot be fully covered here, just to explain what I am more concerned about.
1. Install the plugin
If a small and fresh text editor like VSCode has good support for a programming language, you must install a plugin for the corresponding language. Taking Go as an example, we must at least install the vscode-go plugin. vscode-go is to VSCode, just like vim-go is to VIM. And similar to vim-go, various features implemented by vscode-go also rely on many existing Go peripheral tools, including:
gocode: go get -u -v github.com/nsf/gocode
godef: go get -u -v github.com/rogpeppe/godef
gogetdoc: go get -u -v github.com/zmb3/gogetdoc
golint: go get -u -v github.com/golang/lint/golint
go-outline: go get -u -v github.com/lukehoban/go-outline
goreturns: go get -u -v sourcegraph.com/sqs/goreturns
gorename: go get -u -v golang.org/x/tools/cmd/gorename
gopkgs: go get -u -v github.com/tpng/gopkgs
go-symbols: go get -u -v github.com/newhook/go-symbols
guru: go get -u -v golang.org/x/tools/cmd/guru
gotests: go get -u -v github.com/cweill/gotests / ...
Therefore, to realize which magical features in the demo of the vscode-go official website page, you must install the above dependent tools one by one. If a dependent tool is missing, VSCode will display: "Analysis Tools Missing" in the status bar at the bottom right corner of the window to prompt you to install these tools.
VSCode of course also supports Vim-mode editing mode. If you are like me, like to use vim-mode to edit in VSCode, you can install the VSCodeVim plugin.
There are two ways to install VSCode plugins: online installation and VSIX installation.
Online installation, as the name implies, click the "Extensions" button in the left sidebar of the VSCode window, search for the name of the plugin you want in the Extensions search box that opens, or select pre-made conditions to obtain plugin information. Select the plug-in you want to install and click the "Install" button to complete the installation.
VSIX installation: go to the official website of the plug-in to download the plug-in file to the local (plug-in installation file generally ends in .vsix or .zip), select in the window: "Install from VSIX ...", select the plug-in file you downloaded.
The installed plugins are all placed in the ~ / .vscode / extensions directory (mac and linux).
2. Change the language setting
VSCode will determine the current system language when it is first started, and use the corresponding language as the default window display language. For example: mine is Chinese OS X system, then the default window text of VSCode is Chinese. What should I do if I want to change it to English?
F1 debut! F1 here is not a racing game, but the shortcut key F1. It is estimated that it is also one of the most commonly used shortcut keys for the entire VSCode. After hitting F1, VSCode will display its "Command Palette" input box, which contains all the operation commands that the current VSCode can execute, and supports Search. We enter "language", select "Configure Language" in the search results, VSCode opens a new editing window, load ~ / Library / Application Support / Code / User / locale.json file:
{
// Define the display language of VSCode.
// See https://go.microsoft.com/fwlink/?LinkId=761051 for a list of supported languages.
// To change the value, restart VSCode.
"locale": "zh-cn"
}
The current language is Chinese. If we want to change it to English, modify the "locale" item in the file:
{
// Define the display language of VSCode.
// See https://go.microsoft.com/fwlink/?LinkId=761051 for a list of supported languages.
// To change the value, restart VSCode.
"locale": "en-US"
}
Save and restart VSCode. The VSCode started again will be displayed in English.
3. User Settings and Workspace Settings
UserSettings is a "global" setting, and Workspace Settings, as the name suggests, is a setting for a specific directory or project.
The data set by UserSettings is saved under ~ / Library / Application Support / Code (using mac as an example), and the data set by Workspace Setting is saved in the .vscode directory under a project specific directory.
In the menu bar, select [Preferences-> User Settings] to open the ~ / Library / Application Support / Code / User / settings.json file. By default, the file is empty. VSCode uses the default settings. If you want to personalize the settings, you can copy a copy of the corresponding configuration items to settings.json and assign them new values and save them. The new value will override the default value. Taking the font size as an example, we changed the default editor.fontSize 12 to 10:
// Place your settings in this file to overwrite the default settings
{
"editor.fontSize": 10,
}
After saving, you can see that the size of all the text in the window has become smaller.
In the menu bar, select [Preferences-> Workspace Settings] to open the .vscode settings.json file in the current working directory. Its working principle and configuration method are the same as those of User Settings, but the effective scope is limited to the scope of the workspace.
4. Color Theme
VSCode has built-in mainstream color schemes, such as: monokai, solarized dark / light, etc. F1, enter "color" search, select: "Perefences: Color Theme" (can also be opened on the MAC with cmd + k, cmd + t), select your favorite color theme in the drop-down list, and it will take effect.
Four, the use of vscode-go
As mentioned earlier, like vim-go, the vscode-go plugin implements various functions required in Go coding: automatic format, automatic addition and deletion of import, build on save, lint on save, definition jump, quick prompt of prototype information, automatic Completion, code snippets, etc. In addition, it prompts code problems with colored wavy lines (although sometimes the reaction is a bit slow), including syntax problems, problems that do not meet the idiomatic go rules (such as appId naming, it will suggest you change to appID), etc.
code snippets is very easy to use, the built-in code snippets can be found in ~ / .vscode / extensions / lukehoban.Go-0.6.51 / snippets / go.json, similar to this definition:
//~/.vscode/extensions/lukehoban.Go-0.6.51/snippets/go.json
{
".source.go": {
"single import": {
"prefix": "im",
"body": "import \" $ {1: package} \ ""
},
"multiple imports": {
"prefix": "ims",
"body": "import (\ n \ t \" $ {1: package} \ "\ n)"
},
"single constant": {
"prefix": "co",
"body": "const $ {1: name} = $ {2: value}"
},
"multiple constants": {
"prefix": "cos",
"body": "const (\ n \ t $ {1: name} = $ {2: value} \ n)"
},
"type interface declaration": {
"prefix": "tyi",
"body": "type $ {1: name} interface {\ n \ t $ 0 \ n}"
},
"type struct declaration": {
"prefix": "tys",
"body": "type $ {1: name} struct {\ n \ t $ 0 \ n}"
},
"package main and main function": {
"prefix ":" pkgm ",
"body": "package main \ n \ nfunc main () {\ n \ t $ 0 \ n}"
},
...
Type in the value of "prefix", such as "ims", enter tab, vscode-go will expand for you as:
import (
"package"
)
I have encountered the problem of automatic code completion "failure" when using vscode. vscode-go will only prompt: "PANIC, PANIC, PANIC". After investigation, this is the problem of gocode daemon, my solution is:
gocode close // Close gocode daemon
gocode -s & // Restart it.
V. Summary
Among many lightweight editors, I still prefer VSCODE, after all, it has many years of experience in IDE product development accumulated by Microsoft. And the biggest difference from Microsoft's previous products is that it is an open source project.
For the use of Vscode and the tricks and tricks, please refer to its official document "VS Code Tips and Tricks".
For a list of various peripheral tools and materials of Vscode, please refer to the Awesome-vscode project.
Shortcut keys are often the favorite of developers. VSCode officially produced VSCode shortcut worksheets for three platforms:
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf
VSCode is still developing rapidly, and there is still room for improvement from improvement. For example, during the use process, it is also found that the VSCode window is not responding or the code editing is disordered. However, as an auxiliary editor for Go coding, VSCode is still fully competent and exceeds expectations.
© 2016, bigwhite. All rights reserved.