centos7 Golang vim IDE

接触Golang之后使用过许多的编辑器比如lite,sublime3,goland,lite更适合在windows环境使用,对于非destop版本的Linux就不太适用了,在linux下还是直接上神器vim了,为了快速开发自然要安装许多便捷的插件,先上一张图
首先vim的插件安装有两种形式,一直直接自己安装到~/.vim/plugin目录下 另外一种是使用插件管理器Vundle(还有其他的插件管理器)
开始之前准备一个编辑Go源码的测试源文件,用于验证每个搭建步骤后的变化。
//hello.go
package main
import "fmt"
func main() {
        fmt.Println("Hello Golang!")
}
Vim-go是当前使用最为广泛的用于搭建Golang开发环境的vim插件,这里我同样使用vim-go作为核心和基础进行环境搭建的。vim-go利 用开源Vim插件管理器安装, gmarik/Vundle.vim 是目前被推荐次数更多的Vim插件管理器,超过了 pathogen 。这里我们 就用vundle来作为Vim的插件管理工具。
1、安装Vundle.vim
Vundle.vim的安装步骤如下:
mkdir ~/.vim/bundle
git clone   https://github.com/gmarik/Vundle.vim.git   ~/.vim/bundle/Vundle.vim                                           
创建 ~/.vimrc 文件(如果你没有这个文件的话, 附录为完整的.vimrc文件 ),在文件顶部添加有关Vundle.vim的配置:
filetype off
filetype plugin indent off
set rtp+=$VIM/vimfiles/bundle/vundle/
"rc后的参数表示Vundle自动下载安装插件的位置,为空放在~/.vim/下
call vundle#rc('$VIM/vimfiles/bundle/')
Bundle 'gmarik/vundle'
filetype plugin indent on
syntax on

2、安装Vim-go
编辑 ~/.vimrc ,在 vundle#begin vundle#end 间增加一行:


Plugin 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }

在Vim内执行   :PluginInstall
Vundle.vim会在左侧打开一个Vundle Installer Preview子窗口,窗口下方会提示: “Processing 'fatih/vim-go'” ,待安装完毕后,提示信息变 成“ Done!”。
这时,我们可以看到.vim/bundle下多了一个vim-go文件夹:
$ ls .vim/bundle/
vim-go/  Vundle.vim/
此时,再次编辑hellogo.go, 语法高亮 有了,   保存时自动format (利用$GOBIN/gofmt)也有了,但其他高级功能,比如自动import缺失的 package、自动补齐仍然没有,我们还要继续安装一些东东。
3、安装go.tools Binaries
vim-go安装说明中提到所有必要的binary需要先安装好,
goimports 会自动删除导入import的包
godef 可以跳转到函数定义处
gocode 这个就是go代码自动完成的插件装了YouCompleteMe之后就不需要再点击ctrl x才出现 而是敲代码时自动出现
gotags 这个可以方便你查看源码
通过 :GoInstallBinaries ,这些vim-go依赖的二进制工具将会自动被下载,并被安装到 $GOBIN 下或 $GOPATH/bin 下。(这个工具需要依赖git或hg,需要提前安装到你的OS中。)
:GoInstallBinaries 的执行是交互式的,你需要回车确认:
vim-go: gogetdoc not found. Installing github.com/zmb3/gogetdoc to folder /root/Applications/Go/bin
^@https fetch failed: Get https://golang.org/x/tools/go/buildutil?go-get=1 : dial tcp 216.239.37.1:443: i/o timeout^@package golang.org/x/
tools/go/buildutil: unrecognized import path " golang.org/x/tools/go/buildutil " (https fetch: Get https://golang.org/x/tools/go/buildutil?
go-get=1: dial tcp 216.239.37.1:443: i/o timeout)^@Fetching https://golang.org/x/tools/go/loader?go-get=1 ^@https fetch failed: Get https:
// golang.org/x/tools/go/loader?go-get=1 : dial tcp 216.239.37.1:443: i/o timeout^@package golang.org/x/tools/go/loader : unrecognized impor
t path " golang.org/x/tools/go/loader " (https fetch: Get https://golang.org/x/tools/go/loader?go-get=1 : dial tcp 216.239.37.1:443: i/o tim
eout)^@
vim-go: guru not found. Installing golang.org/x/tools/cmd/guru to folder /root/Applications/Go/bin
Error installing golang.org/x/tools/cmd/guru : Fetching https://golang.org/x/tools/cmd/guru?go-get=1 ^@https fetch failed: Get https://gola
ng.org/x/tools/cmd/guru?go-get=1 : dial tcp 216.239.37.1:443: i/o timeout^@package golang.org/x/tools/cmd/guru : unrecognized import path "
golang.org/x/tools/cmd/guru " (https fetch: Get https://golang.org/x/tools/cmd/guru?go-get=1 : dial tcp 216.239.37.1:443: i/o timeout)^@
vim-go: golint not found. Installing github.com/golang/lint/golint to folder /root/Applications/Go/bin
ch failed: Get https://golang.org/x/lint?go-get=1 : dial tcp 216.239.37.1:443: i/o timeout^@package golang.org/x/lint : unrecognized import
path " golang.org/x/lint " (https fetch: Get https://golang.org/x/lint?go-get=1 : dial tcp 216.239.37.1:443: i/o timeout)^@
vim-go: errcheck not found. Installing github.com/kisielk/errcheck to folder /root/Applications/Go/bin
t=1^@https fetch failed: Get https://golang.org/x/tools/go/loader?go-get=1 : dial tcp 216.239.37.1:443: i/o timeout^@package golang.org/x/
tools/go/loader: unrecognized import path " golang.org/x/tools/go/loader " (https fetch: Get https://golang.org/x/tools/go/loader?go-get=1 :
dial tcp 216.239.37.1:443: i/o timeout)^@ github.com/kisielk/gotool (download)^@
vim-go: impl not found. Installing github.com/josharian/impl to folder /root/Applications/Go/bin
ttps fetch failed: Get https://golang.org/x/tools/imports?go-get=1 : dial tcp 216.239.37.1:443: i/o timeout^@package golang.org/x/tools/im
ports: unrecognized import path " golang.org/x/tools/imports " (https fetch: Get https://golang.org/x/tools/imports?go-get=1 : dial tcp 216.
239.37.1:443: i/o timeout)^@
vim-go: goimports not found. Installing golang.org/x/tools/cmd/goimports to folder /root/Applications/Go/bin
由于众所周知的原因,vim-go的自动安装很可能以失败告终
你可以通过命令安装
#goimports
go get -u golang.org/x/tools/cmd/goimports

也可以根据上 面日志中提到的各个工具的源码地址逐一去下载并本地安装。
可以通过 https://www.golangtc.com/download/package  或者 https://gopm.io/ 下载相关包。
先在你的 $GOPATH 目录(如果不懂 GOPATH,请先弄懂)下,创建目录 src
$ mkdir src
复制   github.com.nsf.gocode.tar.gz     src   目录下,解压缩,这时候目录应该看起来是这个样子:
. └── src
└── github . com
└── nsf
└── gocode
├── LICENSE
├── README . md
├── _gccgo
└── package . go
├── _goremote
...
接下来安装这个包:
$ go install github.com/nsf/gocode/
这时候目录下会生成一个   pkg   目录,里面有编译好的 .a 文件,就可以在 go 文件里使用这个包了。
安装后,$GOBIN下的新增Binaries如下:
[root@iz6r97y3yfzu8dz src]# ls $GOBIN -l
total 147132
-rwxr-xr-x 1 root root  2787103 Jun 17 11:52 asmfmt
-rwxr-xr-x 1 root root 15017165 Jun 15 22:48 dlv
-rwxr-xr-x 1 root root  5474480 Jun 16 23:53 errcheck
-rwxr-xr-x 1 root root  5843192 Jun 15 22:03 fillstruct
-rwxr-xr-x 1 root root 11167455 Jun 16 23:52 gocode
-rwxr-xr-x 1 root root  5830125 Jun 17 11:11 godef
-rwxr-xr-x 1 root root 15742059 Jun 16 23:51 godoc
-rwxr-xr-x 1 root root  6122650 Jun 16 23:52 gogetdoc
-rwxr-xr-x 1 root root  5208106 Jun 16 23:51 goimports
-rwxr-xr-x 1 root root  5660873 Jun 17 00:00 golint
-rwxr-xr-x 1 root root  6481988 Jun 16 23:53 gometalinter
-rwxr-xr-x 1 root root  4209794 Jun 16 23:27 gomodifytags
-rwxr-xr-x 1 root root  5843793 Jun 16 23:51 gorename
-rwxr-xr-x 1 root root  3042035 Jun 17 11:13 gotags
-rwxr-xr-x 1 root root 12120307 Jun 13 08:08 gotour
-rwxr-xr-x 1 root root  8915016 Jun 16 23:51 guru
-rwxr-xr-x 1 root root  8821388 Jun 16 23:52 heapview
-rwxr-xr-x 1 root root  2015916 Jun 10 23:50 hello
-rwxr-xr-x 1 root root  2715393 Jun 16 23:56 iferr
-rwxr-xr-x 1 root root  5173602 Jun 17 00:09 impl
-rwxr-xr-x 1 root root  3448802 Jun 16 23:27 motion
-rwxr-xr-x 1 root root  2719723 Jun 16 23:52 stress
-rwxr-xr-x 1 root root  6258644 Jun 16 23:52 stringer
安装好这些Binaries后,我们来看看哪些特性被支持了。
再次编辑 hello.go
          - 新起一行输入fmt.,然后ctrl+x, ctrl+o,Vim 会弹出补齐提示下拉框,不过并非实时跟随的那种补齐,这个补齐是由gocode提供的。
    – 输入一行代码:time.Sleep(time.Second),执行:GoImports,Vim会自动导入time包。
    – 将光标移到Sleep函数上,执行:GoDef或命令模式下敲入gd,Vim会打开$GOROOT/src/time/sleep.go中 的Sleep函数的定义。执行:b 1返回到hello.go。
    – 执行:GoLint,运行golint在当前Go源文件上。
    – 执行:GoDoc,打开当前光标对应符号的Go文档。
    – 执行:GoVet,在当前目录下运行go vet在当前Go源文件上。
    – 执行:GoRun,编译运行当前main package。
    – 执行:GoBuild,编译当前包,这取决于你的源文件,GoBuild不产生结果文件。
    – 执行:GoInstall,安装当前包。
    – 执行:GoTest,测试你当前路径下地_test.go文件。
    – 执行:GoCoverage,创建一个测试覆盖结果文件,并打开浏览器展示当前包的情况。
    – 执行:GoErrCheck,检查当前包种可能的未捕获的errors。
    – 执行:GoFiles,显示当前包对应的源文件列表。
    – 执行:GoDeps,显示当前包的依赖包列表。
    – 执行:GoImplements,显示当前类型实现的interface列表。
    – 执行:GoRename [to],将当前光标下的符号替换为[to]。
4、其他插件
到目前为止,我们还有若干特性没能实现,重点是:
    – 实时跟随的代码补齐
    – Code Snippet support
(1)、安装YCM(Your Complete Me)
在~/.vimrc中添加一行:
Plugin 'Valloric/YouCompleteMe'
保存退出后,再打开~/.vimrc并执行   :PluginInstall
安装完后重新进入vim,下面的提示栏提示:
[root@iz6r97y3yfzu8dz test]# vim ~/.vimrc
UltiSnips requires py >= 2.7 or py3
YouCompleteMe unavailable: requires Vim compiled with Python (2.7.1+ or 3.4+) support.
请按 ENTER 或其它命令继续

[root@iz6r97y3yfzu8dz test]#vim --version |grep python
HanDevServer:/opt/itest # /opt/iapps/vim/bin/vim --version |grep python
+cryptv +linebreak -python +viminfo
-cscope +lispindent -python3 +vreplace

如果发现是这样的,说明没有加入Python支持,需要重新编译安装vim,加入--enable-pythoninterp=yes参数。如果想开启Python3支持,则--enable-python3interp=yes,所以最终的编译选项是:
HanDevServer:~handaoliang/src/vim74 # ./configure --prefix=/opt/iapps/vim --enable-multibyte --enable-pythoninterp=yes

#如果vim版本不符合就需要卸载旧版本,然后下载最新版本vim
git clone https: //github.com/vim/vim.git
# make一遍的时候,第二遍make时会出现cached,所以第二次make的时候还会使用第一次的执行结果,所以想修改就必须清除make操作之后,两次make
cd vim
make uninstall //卸载
make clean
rm -rf src/auto/config.cache

. /configure --with-features= huge \
--enable- multibyte \
--enable-rubyinterp= yes \
--enable-pythoninterp= yes \
--with-python-config- dir =/usr/lib64/python2. 7 / config \
--enable-perlinterp= yes \
--enable-luainterp= yes \
--enable- cscope \
--prefix=/usr/ local

make && make install
似乎YCM是用了C++编写的模块对性能进行优化了,于是需要手工编译YCM的support库。步骤如下:
sudo apt-get install build-essential cmake python-dev
cd ~/.vim/bundle/YouCompleteMe
./install.sh
构建(编译C++很慢,需要耐心的等一会)ok后,再打开hello.go,逐字的实时补全功能就具备了!Cool!
手动安装方法
因为安装过程中ycm一直安装不成功所以采用手动安装
手动下载完后检查仓库的完整性,切换到   YouCompleteMe  目录下,输入如下命令:

# yum install build-essential cmake python-dev
$ cd ~/.vim/bundle/
$ git clone https: //github.com/ Valloric / YouCompleteMe .git
$ cd YouCompleteMe /  
$ git submodule update --init --recursive
$ cd ~/.vim/bundle/ YouCompleteMe  
$ ./install.py --gocode-completer --clang-completer

(2)、安装 UltiSnips
Vim-go默认是用ultisnips引擎插件,但这个插件需要单独安装。
同样,我们利用vundle来安装它,在~/.vimrc中添加一行:
Plugin 'SirVer/ultisnips'
snippet和snippet引擎是分开的。ultisnips是引擎,vim-go的go snippet定义在这里
编辑hello.go,按照go.snip中的说明,我们输入func后敲击tab键,我们发现期待的:
func name(params) type {
       
}
并没有出现。反倒是YCM的下拉提示显示在那里让你选择。似乎是ultisnips和YCM的键组合冲突了。ultisnips官方说明也的确如 此。ultisnips默认是用Tab展开snippet的,而YCM中的Tab用来选择补齐项,我们可以通过设置来避免这些。
我们在.vimrc中添加如下setting:
" YCM settings
let g:ycm_key_list_select_completion = ['', '']
let g:ycm_key_list_previous_completion = ['']
let g:ycm_key_invoke_completion = '<C-Space>'
" UltiSnips setting
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
这样让YCM通过回车和向下的箭头来做list item正向选择,通过向上箭头做反向选择。通过ctrl+space来原地触发补齐提示。
而ultisnips则是用tab做snippet展开,ctrl+b正向切换占位符,ctrl+z反向切换占位符。
(3)、安装Solarized theme

1. Download and install Tim Pope's Pathogen.
2. Next, move or clone the vim-colors-solarized directory so that it is a subdirectory of the .vim/bundle directory.
a. Clone:
    $ cd ~/.vim/bundle
    $ git clone git://github.com/altercation/vim-colors-solarized.git

b. Move:
In the parent directory of vim-colors-solarized:

    $ mv vim-colors-solarized ~/.vim/bundle/
After either Option 1 or Option 2 above, put the following two lines in your .vimrc:
syntax enable
set background=dark
colorscheme solarized
or, for the light background mode of Solarized:
syntax enable
set background=light
colorscheme solarized
I like to have a different background in GUI and terminal modes, so I can use the following if-then. However, I find vim's background autodetection to be pretty good and, at least with MacVim, I can leave this background value assignment out entirely and get the same results.
if has('gui_running')
set background=light
else
set background=dark
endif

(4)、molokai theme

Molokai theme是TextMate的theme的vim port, 颜色不错,配置比较简单:
mkdir ~ /.vim/colors
下载或复制 https: / / github.com /fatih /molokai/blob /master/colors /molokai.vim到~/ .vim /colors目录下
在.vimrc添加:
colorscheme molokai
set t_Co= 256
set background=dark

(5)、安装NERDTree插件

在.vimrc下面加上: 
Plugin ‘scrooloose/nerdtree’ 
其他步骤与前面安装插件类似,略过。 
下面主要看下.vimrc下面的配置:
"===============================
" NERDTree settings
" ==============================
" F2 to open NERDTree
map <F7> :NERDTreeToggle<CR>

" modify the icon of the tree
" let g:NERDTreeDirArrowExpandable = '+' "let g:NERDTreeDirArrowCollapsible = '-'

" show postion of the window
let g:NERDTreeWinPos = 'left'

" the size of window
let g:NERDTreeSize = 30

" show line num in window
"let g:NERDTreeShowLineNumber = 1

" if show hidden file
"let g:NERDTreeHidden = 0

" open vim, if no file, open NERDTree automatically
" autocmd vimenter * if !argc()|NERDTree|endif

" automatically close when the NERDTree is the only one window
" autocmd bufenter * if (winnr(" $ ")==1 && exists(" b:NERDTree ") &&
" b:NERDTree.isTabTree())|q|endif

" open NERDTree automatically when open vim
" autocmd vimenter * NERDTree</cr></f2>

NERDTree插件启动测试:

  安装好Tagbar插件后,用vim打开go文件,输入“ :NERDTree ”或者按" F7键 "就可以启动 NERDTree 。下面是NERDTree的常用的快捷键和命令:


(6).安装Tagbar插件


1)安装gotags:

  gotags是go语言编写的,直接使用go get命令安装:
go get -u github.com /jstemmer/gotags
 

2)安装ctags:

yum -y   install   ctags
 

3)安装vim Tagbar插件:

在.vimrc下面加上: 
Plugin 'majutsushi/Tagbar'            "函数按类区分,按类折叠显示
其他步骤与前面安装插件类似,略过。 
tagbar支持多种语言,可以参考: 
下面主要看下支持golang的配置,.vimrc下面的配置:

"===============================
" Tagbar settings
" ==============================
" Set width of the Tagbar window
let g :tagbar_width = 30 " map shutcut key for Tagbar, press F8 to open automatically
nmap <F9> :TagbarToggle<CR>  " tagbar usr ctags plugin
let g:tagbar_ctags_bin = 'ctags'
noremap <Leader>y :TagbarToggle<CR> " Display panel with (,y)
" show on left, default is right
" let g:tagbar_left = 1
"开启自动预览(随着光标在标签上的移动,顶部会出现一个实时的预览窗口)                                                  
let g:tagbar_autopreview = 1
" set tagbar window width, default size is 40
let g:tagbar_width = 30

" consur stays on tagbar window , default is on vim window
let g :tagbar_autofocus = 1

" set label not sorted, default is sorted
let g:tagbar_sort = 0

" support golang
let g:tagbar_type_go = {
\ 'ctagstype' : 'go' ,
\ 'kinds' : [
\ 'p:package' ,
\ 'f:function' ,
\ 'v:variables' ,
\ 't:type' ,
\ 'c:const'
\]
\}


注意:g:tagbar_type_go 这里的设置在官方网站上提供了两种方法,由于我安装了ctags,所以采用上面这种设置。
另外一种是基于gotags,其官方配置: https://github.com/jstemmer/gotags  
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
官方图片链接:  使用:光标在某变量或函数上,输入gd跳转 ctrl+o返回

Tagbar插件启动测试:

  安装好Tagbar插件后,用vim打开go文件,输入“ :Tagbar ”或者按" F8 "就可以打开Tagbar。可以使用" CTRL+W+方向键 "实现窗口切换,可以使用“ Ctrl + ] ”跳至函数定义处,然后再使用“ Ctrl + t ”返回。下面是Tagbar的常用的快捷键和命令:
命令
描述
F1
关闭/显示帮助信息;
q
关闭Tagbar窗口;
x
放大/缩小Tagbar窗口;
s
项目排序切换;
+, <kPlus>, zo
展开折叠;
-, <kMinus>, zc
收起折叠;
o, za
折叠收起\展开切换;
*, <kMultiply>, zR
展开所有折叠;
=, zM
收起所有折叠;
回车
转到标签定义处,并且光标跳转到标签定义处;
p
转到标签定义处,但光标停留在Tagbar的窗口;
P
在预览窗口显示标签;
<C-N>
跳到下一个上级标签;
<C-P>
跳到上一个上级标签;
<Space>
显示标签定义;

(7).安装SrcExpl插件

在.vimrc下面加上: 
Plugin ‘wesleyche/SrcExpl’ 
其他步骤与前面安装插件类似,略过。 

"===============================
" SrcExpl settings
" ==============================
" // The switch of the Source Explorer
nmap <F9> :SrcExplToggle<CR>

" // Set the height of Source Explorer window
let g:SrcExpl_winHeight = 8

" // Set 100 ms for refreshing the Source Explorer
let g :SrcExpl_refreshTime = 100

" // Set " Enter " key to jump into the exact definition context
let g:SrcExpl_jumpKey = " <ENTER> "

" // Set "Space" key for back from the definition context
let g :SrcExpl_gobackKey = "<SPACE>"

" // In order to avoid conflicts, the Source Explorer should know what plugins
" // except itself are using buffers. And you need add their buffer names into
" // below listaccording to the command " :buffers! "
let g:SrcExpl_pluginList = [
\ " __Tag_List__ ",
\ " _NERD_tree_ "
\ ]

" // Enable/Disable the local definition searching, and note that this is not
" // guaranteed to work, the Source Explorer doesn't check the syntax for now.
" // It only searches for a match with the keyword according to command 'gd'
let g :SrcExpl_searchLocalDef = 1

" // Do not let the Source Explorer update the tags file when opening
let g:SrcExpl_isUpdateTags = 0

" // Use 'Exuberant Ctags' with '--sort=foldcase -R .' or '-L cscope.files' to
" // create/update the tags file
let g:SrcExpl_updateTagsCmd = " ctags --sort=foldcase -R . "

" // Set "<F12>" key for updating the tags file artificially
let g :SrcExpl_updateTagsKey = "<F12>"

" // Set " <F3> " key for displaying the previous definition in the jump list
let g:SrcExpl_prevDefKey = " <F3> "

" // Set "<F4>" key for displaying the next definition in the jump list
let g :SrcExpl_nextDefKey = "<F4>"

Nerdtree, tagbar, SrcExpl三窗口之间切换可以按ctrl+w+w

附录:.vimrc文件
set nocompatible                      " be iMproved, required
filetype off                          " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
Plugin 'VundleVim/Vundle.vim'         "let Vundle manage Vundle, required
Plugin 'flazz/vim-colorschemes'       "配色插件
Plugin 'scrooloose/nerdtree'          "树形目录
Plugin 'jistr/vim-nerdtree-tabs'      "多标签共用nerdtree
Plugin 'majutsushi/Tagbar'            "函数按类区分,按类折叠显示
Plugin 'wesleyche/SrcExpl'            "自动显示跳转函数及变量定义功能
Plugin 'ctrlpvim/ctrlp.vim'           "查找文件
Plugin 'vim-scripts/indentpython.vim' "自动缩进
Plugin 'vim-syntastic/syntastic'      "静态语法检测
Plugin 'nvie/vim-flake8'              "添加PEP8代码风格检查
Plugin 'fatih/vim-go',{'do':'GoUPdateBinaries'}
Plugin 'SirVer/ultisnips'             " func 自动补齐
Plugin 'Valloric/YouCompleteMe'       "代码自动补齐

" All of your Plugins must be added before the following line
call vundle#end()                     " required

filetype plugin indent on             " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" System vimrc file for MacVim
"
"================================
" YCM settings
" ===============================
let g:ycm_key_list_select_completion = ['','']
let g:ycm_key_list_previous_completion = ['']
let g:ycm_key_invoke_completion = '<C-Space>'

"================================
" UltiSnips settings
"================================
let g:UltiSnipsExpandTrigger = "<tab>"
let g:ULtiSnipsJumpForwardTrigger = "<c-b>"
let g:UltiSnipsJumpBackwardTrigger = "<c-z>"

"===============================
" Theme settings
"===============================

syntax enable                           "语法高亮
"set background=light                     "设置背景色
set background=dark                     "设置背景色
"colorscheme solarized                   "主题
set t_Co=256
colorscheme molokai                   "主题
set nocompatible                        "关闭对 vi 的兼容
set nu                                  "设置行号

" The default for 'backspace' is very confusing to new users, so change it to a
" more sensible value.  Add "set backspace&" to your ~/.vimrc to reset it.
set backspace+=indent,eol,start

" Disable localized menus for now since only some items are translated (e.g.
" the entire MacVim menu is set up in a nib file which currently only is
" translated to English).

"======================================
"静态语法检测
"======================================
let g:syntastic_lua_checkers = ['luacheck']
let python_highlight_all=1
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
"======================================
"NERDTree settings
"======================================
map <F2> :NERDTreeToggle<CR>            "设置f2为打开、关闭NERDTree快捷键
let g:NERDTreeWinPos="left"             "靠左显示
let g:NERDTreeWinSize=25                "最大长度
let g:NERDTreeShowLineNumbers=1         "显示行号
let NERDTreeShowHidden=1                "是否显示隐藏文件
let g:nerdtree_tabs_open_on_console_startup=1 " 在终端启动vim时,共享NERDTree,用于打开多个标签页的情况
let NERDTreeIgnore=['\.pyc','\~$','\.swp'] " 忽略一下文件的显示
" let NERDTreeShowBookmarks=1           " 显示书签列表
let NERDTreeHighlightCursorline = 1     "高亮当前行
let g:NERDTreeAutoCenter=1
let g:neocomplcache_enable_at_startup = 1
"从NERDTree打开文件后自动关闭NERDTree
let g:NERDTreeQuitOnOpen=1
" 在终端启动vim时,共享NERDTree
" 显示书签列表
"autocmd vimenter * NERDTree            "打开vim默认打开nerdtree
"autocmd VimEnter * wincmd p            "打开vim默认光标位置在文件中

" Highlight current line
au WinLeave * set nocursorline nocursorcolumn
au WinEnter * set cursorline cursorcolumn
set cursorline cursorcolumn

" Display tabs at the beginning of a line in Python mode as bad.
au BufRead,BufNewFile *.py,*.pyw match CursorLineNr /^\t\+/
" Make trailing whitespace be flagged as bad.
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match CursorLineNr /\s\+$/

"===============================
"syntax light on
"===============================
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1

"===============================
" Tagbar settings
" ==============================
" Set width of the Tagbar windowlet g:tagbar_width = 30" map shutcut key for Tagbar, press F8 to open automatically
nmap <F9> :TagbarToggle<CR>
let g:tagbar_ctags_bin = 'ctags'
noremap <Leader>y :TagbarToggle<CR> " Display panel with (,y)
"show on left, default is right
"let g:tagbar_left = 1
"开启自动预览(随着光标在标签上的移动,顶部会出现一个实时的预览窗口)
let g:tagbar_autopreview = 1
" set tagbar window width, default size is 40"
let g:tagbar_width = 30
"consur stays on tagbar window, default is on vim window
let g:tagbar_autofocus = 1
"set label not sorted, default is sorted
let g:tagbar_sort = 0
" support golang
let g:tagbar_type_go = {
            \ 'ctagstype' : 'go',
            \ 'kinds' : [
            \ 'p:package',
            \ 'i:imports:1',
            \ 'c:constants',
            \ 'v:variables',
            \ 't:types',
            \ 'n:interfaces',
            \ 'w:fields',
            \ 'e:embedded',
            \ 'm:methods',
            \ 'r:constructor',
            \ 'f:functions'
            \ ],
            \ 'sro' : '.',
            \ 'kind2scope' : {
            \ 't' : 'ctype',
            \ 'n' : 'ntype'
            \ },
            \ 'scope2kind' : {
            \ 'ctype' : 't',
            \ 'ntype' : 'n'
            \ },
            \ 'ctagsbin' : 'gotags',
            \ 'ctagsargs' : '-sort -silent'
            \ }

"===============================
" SrcExpl settings
" ==============================
"// The switch of the Source Explorer
nmap <F10> :SrcExplToggle<CR>
" // Set the height of Source Explorer window
" let g:SrcExpl_winHeight = 8
"
" " // Set 100 ms for refreshing the Source Explorer
let g:SrcExpl_refreshTime = 100

" // Set "Enter" key to jump into the exact definition context
let g:SrcExpl_jumpKey = "<ENTER>"
"
" // Set "Space" key for back from the definition context
let g:SrcExpl_gobackKey = "<SPACE>"

" // In order to avoid conflicts, the Source Explorer should know what plugins
" // except itself are using buffers. And you need add their buffer names into
" // below listaccording to the command ":buffers!"
let g:SrcExpl_pluginList = [
\ "__Tag_List__",
\ "_NERD_tree_"
\ ]

" // Enable/Disable the local definition searching, and note that this is not
" // guaranteed to work, the Source Explorer doesn't check the syntax for now.
" // It only searches for a match with the keyword according to command 'gd'
let g:SrcExpl_searchLocalDef = 1

" // Do not let the Source Explorer update the tags file when opening
let g:SrcExpl_isUpdateTags = 0

" // Use 'Exuberant Ctags' with '--sort=foldcase -R .' or '-L cscope.files' to
" // create/update the tags file
let g:SrcExpl_updateTagsCmd = "ctags --sort=foldcase -R ."

" // Set "<F12>" key for updating the tags file artificially
let g:SrcExpl_updateTagsKey = "<F12>"

" // Set "<F3>" key for displaying the previous definition in the jump list
let g:SrcExpl_prevDefKey = "<F3>"

" // Set "<F4>" key for displaying the next definition in the jump list
let g:SrcExpl_nextDefKey = "<F4>"
"=====================================
"设置缩进
"====================================
set tabstop=4
set softtabstop=4
set shiftwidth=4
set textwidth=120
set showmatch
set expandtab
set autoindent
set fileformat=unix
set nohls
set guifont=Consolas:h14

set encoding=utf-8
set langmenu=zh_CN.UTF-8
"=====================================
"解决菜单乱码
"=====================================
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解决consle输出乱码
language messages zh_CN.UTF-8

"默认最大化窗口打开
au GUIEnter * simalt ~x


猜你喜欢

转载自blog.csdn.net/yuexiaxiaoxi27172319/article/details/80718445
今日推荐