我尝试安装了vim-go(耗时15分钟)

简要概括

尽管有许多Golang的开发环境可供选择,但在B2B现场中,例如未获准引入IntelliJ,软件安装存在障碍,可能无法引入所需的IDE。在这其中,相对较容易引入的是vim,我们将配置Golang的开发环境,并在最小必要的情况下进行设置。
我们将从官方安装vim-go插件。

本文介绍了在虚拟环境中安装vim-go的步骤。

前提是一个特定的条件或假设,其必须被满足或接受,才能继续进行或实现某事。

    仮想環境上にgolangがインストールされている。こちらで環境を構築する

步骤

1. 如前所述,按照这个步骤来建立环境。

2. 从终端连接到Vagrant进行SSH。

$ cd /path/to/vagrant/golang/vagrant
$ vagrant ssh

安装 NeoBundle。

[vagrant@develop ~]$ curl https://raw.githubusercontent.com/Shougo/neobundle.vim/master/bin/install.sh > install.sh
[vagrant@develop ~]$ sh ./install.sh
[vagrant@develop ~]$ rm -rf install.sh

在主目录下创建一个名为.vimrc的文件。

[vagrant@develop ~]$ vi ~/.vimrc
set encoding=utf-8
set fileencodings=iso-2022-jp,euc-jp,sjis,utf-8
set fileformats=unix,dos,mac

" Note: Skip initialization for vim-tiny or vim-small.
if 0 | endif

if &compatible
  set nocompatible               " Be iMproved
endif

" Required:
set runtimepath^=~/.vim/bundle/neobundle.vim/

" Required:
call neobundle#begin(expand('~/.vim/bundle/'))

" Let NeoBundle manage NeoBundle
" Required:
NeoBundleFetch 'Shougo/neobundle.vim'

" My Bundles here:
" Refer to |:NeoBundle-examples|.
" Note: You don't set neobundle setting in .gvimrc!

call neobundle#end()

" Required:
filetype plugin indent on

" If there are uninstalled bundles found on startup,
" this will conveniently prompt you to install them.
NeoBundleCheck

打开 vim。

[vagrant@develop ~]$ vim

当安装开始时,请输入y。

Not installed bundles:  ['vim-go']
Install bundles now?
(y)es, [N]o:

7. 结束之后,使用 :q 命令关闭 vim。

在.vimrc的下面添加并保存以下行。注:不要在.gvimrc中设置neobundle设置!

NeoBundle 'fatih/vim-go'

9. 当再次启动vim时,会询问是否要安装vim-go插件,此时输入”y”并开始安装。

Not installed bundles:  ['vim-go']
Install bundles now?
(y)es, [N]o:

在完成后,使用`:q`关闭vim,然后重新启动vim。

11. 在 vim 中输入 “:GoInstallBinaries”,开始安装 Go 包。安装会如下所示开始。

vim-go: gocode not found. Installing github.com/nsf/gocode to folder /home/vagrant/go/bin/

vim-go: gometalinter not found. Installing github.com/alecthomas/gometalinter to folder /h
ome/vagrant/go/bin/
vim-go: goimports not found. Installing golang.org/x/tools/cmd/goimports to folder /home/v
agrant/go/bin/
vim-go: godef not found. Installing github.com/rogpeppe/godef to folder /home/vagrant/go/b
in/
vim-go: oracle not found. Installing golang.org/x/tools/cmd/oracle to folder /home/vagrant
/go/bin/
vim-go: gorename not found. Installing golang.org/x/tools/cmd/gorename to folder /home/vag
rant/go/bin/
vim-go: golint not found. Installing github.com/golang/lint/golint to folder /home/vagrant
/go/bin/
vim-go: errcheck not found. Installing github.com/kisielk/errcheck to folder /home/vagrant
/go/bin/
vim-go: gotags not found. Installing github.com/jstemmer/gotags to folder /home/vagrant/go
/bin/
vim-go: asmfmt not found. Installing github.com/klauspost/asmfmt/cmd/asmfmt to folder /hom
e/vagrant/go/bin/
Press ENTER or type command to continue

结束了。

确认操作

使用下列命令创建新的Go文件。

vim main.go

写下以下乱七八糟的代码格式

package        main

import              "fmt"

func   main() {

}

当执行以下命令时

:GoFmt

会有一些格式限制。

package main

import "fmt"

func main() {
}

在main函数内,输入”fmt.”,然后按住control键并输入x,o,会触发以下的输入补全功能。

スクリーンショット 2016-03-09 00.15.50.png

执行下列命令将

:GoRun

我可以执行这个任务

vim main.go

Hello vim-go!

Press ENTER or type command to continue

辛苦了!

请参照下列文本原文的中文同义句:
提供以下内容供参考。

    vim-go公式ページ
bannerAds