This post was published by Librant

If I said VIM was the best editor to use in a Linux environment, most people would turn up their noses at me. VIM is probably the most difficult of the many editors he has used. I use cloud virtual machine in our company, to tell the truth, here is a joke, it is a real card, didn’t open a few web pages, open a few software card don’t don’t, later code code, can use Linux machine I try to use Linux environment, if the reader happens to be a Gopher, then I strongly suggest you use VIM, Vim-go is currently the most widely used Vim plug-in for building Golang development environment. All right, without further ado, let’s look at the interface I built.

In fact, Vim has a lot of plug-ins, which can make Vim very good. When readers look up relevant information and know the various parameters of Vim, they can build different styles of Go development environment according to their own preferences. So without further ado, turn on. (Read the first chapter of Follow Me Docker first.)

1.1 Environment Preparations

Once the Go compiler is installed, you can build Go-Vim. The first step is to create the.vim directory and.vimrc file in the current user’s HOME directory:

librant@ubuntu:~$ mkdir .vim

librant@ubuntu:~$ touch .vimrc

Once created, go to.vim and download vim’s plug-in manager bundle:

librant@ubuntu:~/.vim$ mkdir bundle

Then go to the bundle directory and install vundle.vim:

librant@ubuntu:~/. Vim/ bundle$git clone git clone github.com/VundleVim/V…

Once the download is complete, the vundle.vim directory is generated in the current directory

Go to the bundle directory and install vim-go:

Librant @ ubuntu: ~ / vim/bundle $git clone github.com/fatih/vim-g…

Once the download is complete, the vim-go directory is generated in the current directory

1.2 Plug-in Installation

The ~/ (user $HOME) directory already has.vimrc file, do not need to create. (” for comments).

1.2.1 installationVundle.vim

Add the following configuration to the.vimrc file:

set nocompatible

filetype off

set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()

Plugin ‘gmarik/Vundle.vim’

call vundle#end()

filetype plugin indent on

Save the Settings and exit.

1.2.2 Install Vim – go

Continue editing the.vimrc file and add the following configuration between call vundle#begin() and call vundle#end() :

Plugin ‘fatih/vim-go’

Once saved, reopen the Vim editor and type PluginInstall on the command line

:PluginInstall

After execution, a list of plug-ins to install appears on the left, with the.vimrc file on the right. As shown in Figure 1-2-2:

At the beginning of execution, the Processing process will appear in the lower left corner. Wait a little while. This is after downloading the code. “, indicating that the installation is complete.

1.2.3 Install the go. The tools Binaries

The binary tools associated with Go are required for the VIm-Go installation. Due to historical reasons, Google tools cannot be downloaded and installed by themselves. GitHub tools can be installed successfully.

First open the.vimrc file, switch to the command line mode, and run the GoInstallBinaries command to install yourself.

:GoInstallBinaries

Wait until the tool dependent on Vim-go is automatically installed. If the installation is successful, it will be generated in the $GOPATH/bin directory. After installation, see Figure 1-2-3:

Since some command files cannot be installed automatically, you need to install them manually. First of all, compare the directories to see which commands have not been installed, then search gitHub to find the corresponding command source code, use Git Clone to download to the local, and then use go install command to install. I’ve already explained how to install it, so I won’t repeat it here.

GitHub path for related tools:

Golint: github.com/golang/lint…

Gocode: github.com/nsf/gocode….

Errcheck: github.com/kisielk/err…

Gotags: github.com/jstemmer/go…

(Lack of what tools, basic can be found, here is not a list)

1.3 VIM theme colors

Vim’s theme colors stored in the/usr/share/Vim/vim80 / colors directory, if there is no theme directory, just need to download it himself. Color themes downloaded to this directory will be available to all users, but if you only want to use them under the current user, you can put the downloaded themes in the ~/.vim/colors directory. I prefer the Molokai theme style, here is a brief introduction to download this theme.

1) Search for the Molokai topic on gitHub and find the Git repository tomasr/ Molokai for the topic

2) Go to the.vim directory and use Git Clone to download the topic

Librant @ ubuntu: ~ / vim $git clone github.com/tomasr/molo…

3) after the download is complete, copy molokai/colors/molokai. Vim files into the ~ /. Vim/colors directory

4) Configure the. Vimrc file and add the following information to the file:

set t_Co=256

colorscheme molokai

let g:molokai_original = 1

let g:rehash256 = 1

If you need to configure other topics, you only need to set the corresponding topic name.

1.4 Installing Other Plug-ins

1.4.1 SirVer/ultisnips

UltiSnips is Vim’s snippet tool. It’s just an engine that needs to be used with Vim-Snippets. Vim-snippets predefined code templates commonly used in dozens of languages. Located in ~/.vim/bundle/vim-snippets/UltiSnips/, UltiSnips has its own set of code template syntax rules.

The configuration in.vimrc is as follows:

Plugin ‘honza/vim-snippets’

Plugin ‘SirVer/ultisnips’

“Insert mode triggers code block completion of UltiSnips directly through the key

let g:UltiSnipsExpandTrigger=””

“Pops up a list of available UltiSnips, set to a special mapping because it is not often used

let g:UltiSnipsListSnippets=””

Jump to the next code block editable area

let g:UltiSnipsJumpForwardTrigger=””

“Jump to the previous code block editable area

let g:UltiSnipsJumpBackwardTrigger=””

Add locations such as go-Vim are the same, and the installation process is similar.

The gitHub code path looks like this:

Honza/vim – snippets: github.com/honza/vim-s…

SirVer/ultisnips: github.com/SirVer/ulti…

1.4.2 scrooloose/nerdtree

NERDTree lists the directory tree of the current path, which is common in ides. You can easily browse the overall directory structure of the project and create and delete rename files or file names.

The configuration in.vimrc is as follows:

Plugin ‘scrooloose/nerdtree’

“Setting NerdTree

map :NERDTreeMirror

map :NERDTreeToggle

After entering vim, you can press F7 to show and hide the NERDTree area.

The gitHub code path looks like this:

Scrooloose/nerdtree: github.com/scrooloose/…

1.4.3 majutsushi/tagbar

Tagbar allows you to create an outline view of the file you are editing, including interfaces/methods/variables, etc. You can check to quickly jump to the target location. Editing large files is especially useful.

Since tagbar is based on Ctags, you need to install Ctags first:

root@ubuntu:/# apt-get install ctags

The configuration in.vimrc is as follows:

“F9 triggers, set width to 30

let g:tagbar_width = 30

nmap :TagbarToggle

“Enable automatic preview (a live preview window appears at the top as the cursor moves over the TAB)

let g:tagbar_autopreview = 1

“Turn off sorting, that is, sorting by the position of the labels themselves in the file

let g:tagbar_sort = 0

After entering VIm, you can press F9 to turn tagbar on and off.

The gitHub code path looks like this:

Majutsushi/the tagbar: github.com/majutsushi/…

1.4.4 Raimondi/delimitMate

DelimitMate is a plug-in for automatically completing quotation marks (single/double/back) and parentheses (()[]{}).

The configuration in.vimrc is as follows:

Plugin ‘Raimondi/delimitMate’

The gitHub code path looks like this:

Raimondi/delimitMate: github.com/Raimondi/de…

GO language debugging tool – DLV

Vim create program files automatically add header comments

Appendix: Analysis of VIM parameter Settings

  1. Set Nocompatible: Do not use VI’s keyboard mode, but Vim’s own
  2. Set number: displays the line number
  3. Set showcmd: The command is displayed
  4. Syntax on: turns on syntax highlighting
  5. Filetype on: checks the filetype