主要是在vim中通过vundle来安装vim-go插件、gocode插件,支持代码高亮、代码提示以及语法检查等功能
安装Golang 1.11.2
curl -Lo golang.tar.gz https://dl.google.com/go/go1.11.2.linux-amd64.tar.gz
tar zxf golang.tar.gz -C /opt
mkdir -p /home/golang/{go,other}
在/etc/profile尾部添加
export GOPATH=/home/golang/go:/home/golang/other #多个工作目录用:分隔
export PATH=$PATH:$GOROOT/bin:${GOPATH//://bin:}/bin
source /etc/profile
安装Vim 8.1
卸载旧版本的vim
yum remove vim vim-common vim-minimal #注意卸载vim-minimal会卸载sudo
# 安装vim 8
curl -Lo vim8.tar.gz https://github.com/vim/vim/archive/v8.1.0513.tar.gz
tar zxf vim8.tar.gz
cd vim-8.1.0513
yum install gcc ncurses ncurses-devel
./configure \
--with-features=huge \
--enable-pythoninterp=yes \
--enable-cscope \
--enable-fontset \
--with-python-config-dir=/usr/lib64/python2.7/config
说明:
–with-features=huge:支持最大特性
–enable-rubyinterp:打开对ruby编写的插件的支持
–enable-pythoninterp:打开对python编写的插件的支持
–enable-python3interp:打开对python3编写的插件的支持
–enable-luainterp:打开对lua编写的插件的支持
–enable-perlinterp:打开对perl编写的插件的支持
–enable-multibyte:打开多字节支持,可以在Vim中输入中文
–enable-cscope:打开对cscope的支持
–with-python-config-dir=/usr/lib64/python2.7/config 指定python 路径
–with-python-config-dir=/usr/lib64/python3.5/config 指定python3路径
vim --version | grep python #查看vim是否包含对python的支持
make
make install #会安装到/usr/local/bin/vim
安装vim插件管理工具vundle
yum install git
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
编辑~/.vimrc 进行配置
syntax on
"set nu
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
call vundle#end()
filetype plugin indent on
打开vim 输入:PluginInstall 将自动安装插件
之后的安装插件安装,仅需添加Plugin 'xxx'语句到~/.vimrc文件中
安装Go语言代码检查和高亮插件vim-go
在~/.vimrc中添加 Plugin 'fatih/vim-go'
打开vim 输入:PluginInstall
默认代码并不会高亮显示,需要配置,编辑~/.vimrc文件
syntax on
"set nu
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'fatih/vim-go'
call vundle#end()
filetype plugin indent on
let g:go_version_warning = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
安装代码补全工具YouCompleteMe
在~/.vimrc中添加 Plugin 'Valloric/YouCompleteMe'
打开vim 输入:PluginInstall
# 这个过程比较慢 会下载大约225MB文件
YMC安装完成后,需要编译才能使用,编译时要选择支持的语言,这里选择Golang
cd ~/.vim/bundle/YouCompleteMe/
yum install cmake python-devel gcc-c++
./install.sh --go-completer
设置tab键为4个空格
在~/.vimrc中添加
set nocompatible
set backspace=indent,eol,start
#设置tab为四个空格
set ts=4
set expandtab
安装目录结构展示插件nerdtree
在~/.vimrc中添加 Plugin 'scrooloose/nerdtree'
打开vim 输入:PluginInstall
自动启用
在.vimrc中添加 autocmd vimenter * NERDTree
安装代码结构展示插件Tagbar
go get -u github.com/jstemmer/gotags
yum install ctags
在~/.vimrc中添加 Plugin 'Tagbar'
打开vim 输入:PluginInstall
使用时,输入 :Tagbar
最终效果:
.vimrc文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
set nocompatible set ts=4 set expandtab set backspace=indent,eol,start syntax on "set nu filetype off set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'VundleVim/Vundle.vim' Plugin 'fatih/vim-go' Plugin 'Valloric/YouCompleteMe' Plugin 'scrooloose/nerdtree' Plugin 'Tagbar' call vundle#end() filetype plugin indent on let g:go_version_warning = 1 let g:go_highlight_types = 1 let g:go_highlight_fields = 1 let g:go_highlight_functions = 1 let g:go_highlight_function_calls = 1 let g:go_highlight_operators = 1 let g:go_highlight_extra_types = 1 autocmd vimenter * NERDTree |
附:
rpm包下载:https://centos.pkgs.org/
# vim 8的rpm包
http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64//vim-common-8.0.003-1.gf.el7.x86_64.rpm
http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64//vim-enhanced-8.0.003-1.gf.el7.x86_64.rpm
# 安装
yum install vim-common-8.0.003-1.gf.el7.x86_64.rpm vim-enhanced-8.0.003-1.gf.el7.x86_64.rpm
参考:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
"========================================== "通用 "========================================== "history存储长度 set history=1000 "检测文件类型 filetype on "针对不同的文件类型采用不同的缩进格式 filetype indent on "允许插件 filetype plugin on "启动自动补全 filetype plugin indent on "兼容vi模式。去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限 set nocompatible "文件修改之后自动载入 set autoread "启动时不显示那个援助索马里儿童的提示 set shortmess=atI "取消备份 set nobackup set nowb set noswapfile "粘贴时保持格式 set paste "- 则点击光标不会换,用于复制 set mouse-=a " 在所有的模式下面打开鼠标 set selection=exclusive set selectmode=mouse,key "去掉输入错误的提示声音 set noerrorbells set novisualbell set t_vb= set tm=500 "========================================== " 显示和格式 "========================================== "显示行号 set number "取消换行 set nowrap "为方便复制,用<F6>开启/关闭行号显示 nnoremap <F6> :set nonumber!<CR>:set foldcolumn=0<CR> "括号配对情况 set showmatch "How many tenths of a second to blink when matching brackets set mat=2 "高亮search命中的文本。 set hlsearch "搜索时忽略大小写 set ignorecase "随着键入即时搜索 set incsearch "有一个或以上大写字母时仍大小写敏感 set smartcase "代码折叠 set foldenable "折叠方法 " manual 手工折叠 " indent 使用缩进表示折叠 " expr 使用表达式定义折叠 " syntax 使用语法定义折叠 " diff 对没有更改的文本进行折叠 " marker 使用标记进行折叠, 默认标记是 {{{ 和 }}} set foldmethod=syntax "设置Tab键的宽度 [等同的空格个数] set foldcolumn=4 set tabstop=4 set shiftwidth=4 set expandtab " 将Tab自动转化成空格 [需要输入真正的Tab键时,使用 Ctrl+V + Tab] "按退格键时可以一次删掉 4 个空格 set softtabstop=4 set ai "Auto indent set si "Smart indent "========================================== "状态 "========================================== "显示当前的行号列号 set ruler "在状态栏显示正在输入的命令 set showcmd "Set 7 lines to the cursor - when moving vertically using j/k 上下滚动,始终在中间 set so=7 "突出显示当前行 set cursorline |
转载请注明:轻风博客 » CentOS7系统基于Vim8搭建Go语言开发环境