配置linux下go开发环境-Vim

  1. 新建~/.vimrc文件
vim .vimrc

定制当前用户的vim配置
根据这个文章里的自己添加了一些配置
很好很强大的vimrc(带注释版)
2. 安装Vundle.vim插件
参考了这篇文章,写的很详细
Golang开发环境搭建-Vim篇

mkdir ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

在.vimrc文件顶部添加有关Vundle.vim的配置:

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()

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
  1. 安装vim-go
    编辑~/.vimrc,在vundle#begin和vundle#end间增加一行:
Plugin 'faith/vim-go'

在Vim内执行 :PluginInstall
这里我执行了两次才可以
由于安装的vim-go版本要求vim版本比较高,查了下升级太麻烦,按照提示,在配置文件里加了一句

let g:go_version_warning = 0
  1. 修改配色

下载了配色文件https://raw.githubusercontent.com/encody/nvim/master/colors/molokai.vim
放在~/.vim/colors/中就可以了

  1. go.tools Binaries

使用:GoInstallBinaries果然失败。自己手动装吧
参考:https://blog.csdn.net/xxy0403/article/details/53909252

  • guru gorename goimports
cd $GOPATH/src
mkdir -p golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/tools
cd ../../
go install golang.org/x/tools/cmd/guru
go install golang.org/x/tools/cmd/gorename/
go install golang.org/x/tools/cmd/goimports/
  • golint
ethan@ethan-virtual-machine:~/go$ git clone https://github.com/golang/lint
mv lint/ ./src/golang.org/x/
ethan@ethan-virtual-machine:~/go/src$ go install golang.org/x/lint/golint/
  • keyfiy
go get honnef.co/go/tools/cmd/keyify

除了上面的,其他地址是github的是可以自动装的。
在这里插入图片描述
详情可以看下面的文件
~/.vim/bundle/vim-go/plugin/go.vim
在这里插入图片描述
最后终于看到了下面的
在这里插入图片描述

5.安装YCM
在./vimrc中添加,重启,然后PluginInstall

Plugin 'Valloric/YouCompleteMe'

在这里插入图片描述
太慢了,等了半天,最后取消了。
手动下载
然后按官方的文档里的安装

cd ~/.vim/bundle
git clone https://github.com/Valloric/YouCompleteMe.git
cd YouCompleteMe/
//之前忘了这句,会报错的
git submodule update --init --recursive
sudo apt install build-essential cmake python3-dev
cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all

但是这里报错了。
在这里插入图片描述
查了下似乎是安装clang的问题,还是不能省啊

sudo apt-get update
sudo apt install clang
python3 install.py --all --system-libclang

然后又报错了。。绝望
在这里插入图片描述

接着昨天的来,我先注释掉了.vimrc中的,然后用PluginClean卸载之前装过的。

"Plugin 'Valloric/YouCompleteMe'

然后重新下载了一次

cd ~/.vim/bundle
git clone https://github.com/Valloric/YouCompleteMe.git
cd YouCompleteMe/
//之前忘了这句,会报错的
git submodule update --init --recursive

然后删掉之前的注释
打开果然看到了下面的提示
在这里插入图片描述
参考:Ubuntu 16.04 下快速安装和配置YouCompleteMe插件

sudo apt install python-dev python3-dev 
sudo apt install build-essential cmake

看下图发现还是自己下载了libclang,好像前面的clang白装了
在这里插入图片描述
第一次装好以后提示没有.ycm_extra_conf.py文件
而且找不到go的可执行文件
又重新运行了一下

sudo python3 install.py --go-completer

结果竟然可以运行了。。虽然还是没有那个文件,但是没有提示了。
把./.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py移动到.vim/下面,然后在flags中添加了

'-isystem',
'/usr/include/c++/5.4.0',
'-isystem',
'/usr/include/x86_64-linux-gnu/c++/',

然而上面的重新运行坑死了我。。
折腾了半天,YcmDiags报错说Native filetype completion not supported for current file, cannot force recompilation.
YcmDebugInfo 显示server has clang support compiled in false
查了下是因为第二次安装没有加–clang-completer
加了以后,重新装了一次,就好了。。。心累

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值