vim-go插件安装

post thumb
Golang
作者 Louis 发表于 2020年7月8日

[TOC]

前言

vim是linux系统下常用的代码编辑器,默认情况下不支持go的代码高亮和语法检查,不过可以通过安装vim插件来支持go的开发 Vim-go是当前使用最为广泛的用于搭建Golang开发环境的vim插件,这里我同样使用vim-go作为核心和基础进行环境搭建的。vim-go利 用开源Vim插件管理器安装,gmarik/Vundle.vim是目前被推荐次数更多的Vim插件管理器.

安装后是这样的

安装

基于vundle安装.

$ git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go
$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

配置vim如下,:wq保存后, 再次进入vim执行PluginInstall命令. 这里我顺便安装了YouCompleteMe插件, 实现了实时补全.

$ vim ~/.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()
"
" " let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'fatih/vim-go'
"https://github.com/fatih/vim-go
Plugin 'https://github.com/Valloric/YouCompleteMe'
" " All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

"options
set number
set autoindent
set shiftwidth=4
set ts=4
set expandtab
set softtabstop=4
set paste
set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1
set termencoding=utf-8
set fileformats=unix
set encoding=utf-8

YouCompleteMe安装

基于python3 编译安装, 需要用到的依赖build-essential cmake vim python3-dev python3-pip

$ sudo apt install build-essential cmake vim python3-dev python3-pip
$ cd .vim/bundle/YouCompleteMe
$ python3 install.py --go-completer

The ycmd server SHUT DOWN (restart with …low the instructions in the documentation.

打开vi, 这个会有一个提示, 一般是查看具体的文件日志/tmp/ycmd_45801_stderr__5ne0_yu.log, 我的是在这个文件里面. 报的是pathtools not installed, 这里安装一下即可. 具体错误可以具体分析.

$ tail -f /tmp/ycmd_34409_stderr_4efg2b09.log
    from ycmd import extra_conf_store, hmac_plugin, server_state, user_options_store
  File "/home/louis/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/server_state.py", line 22, in <module>
    from ycmd.completers.language_server import generic_lsp_completer
  File "/home/louis/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/generic_lsp_completer.py", line 19, in <module>
    from ycmd.completers.language_server import language_server_completer
  File "/home/louis/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 28, in <module>
    from watchdog.events import PatternMatchingEventHandler
  File "/home/louis/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/watchdog_deps/watchdog/build/lib3/watchdog/events.py", line 91, in <module>
    from pathtools.patterns import match_any_paths
ModuleNotFoundError: No module named 'pathtools'

这里我们安装pathtools即可

$ sudo pip3 install pathtools
Tags:
上一篇
git-rebase合并多commit记录