如何在windows 下配置vim+youcompleteme(python3)
vim是我最喜欢的编辑器。因为我编程不喜欢移动鼠标。也不喜欢用上下箭头。其他如录制宏和快捷操作爱不释手。虽然大神们喜欢Linux,但是我还是喜欢windows。因为可以打游戏。好了,不废话了。来点干货,如何在windows下配置youcompleteme。默认Python3.7已经装好,并且已经把python加入到环境变量。
第一步 下载我们需要的VIM
去vim的官网 https://www.vim.org/ 下载,当然不是普通的vim版本。Youcompleteme是需要vim的python支持的。最后跳转到github
https://github.com/vim/vim-win32-installer/releases/tag/v8.1.2058
下载完相应的版本,我用的是64位签名版。
https://github.com/vim/vim-win32-installer/releases/download/v8.1.2058/gvim_8.1.2058_x64_signed.exe
下载安装VIM,为了改VIM方便。强烈不建议安装在C盘(因为修改VIMRC时候经常需要管理员权限)
安装完VIM后查看一下VIM的版本在windows CMD 下输入gvim --version(如果你
版本中有+python3/dyn vim就完成了。如果提示你命令不存在。需要在windows环境变量下加入你的vim路径。不会的自行百度)
第二步下载 Visual C++ Build Tools
当然我们也是官网下载,据官网上说2019版本兼容2017,下2019就好了。
https://visualstudio.microsoft.com/visual-cpp-build-tools/
第三步安装Vundle (可以和第二步并行操作)当然也是去官网
https://github.com/VundleVim/
查看windows的安装步骤。
https://github.com/VundleVim/Vundle.vim/wiki/Vundle-for-Windows
git和curl是必须的。
git
https://git-scm.com/
curl
https://curl.haxx.se/
安装后确认环境变量已经配置好。可以用git --version 和curl --version
C:\Users\Administrator>git --version
git version 2.23.0.windows.1
C:\Users\Administrator>curl --version
curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL
Release-Date: [unreleased]
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL
下载clone Vundle,把它放在VIM的路径下。
D:\Program Files\Vim>git clone https://github.com/VundleVim/Vundle.vim.git "d:\program files\vim\bundle\Vundle.vim"
Cloning into 'd:\program files\vim\bundle\Vundle.vim'...
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
Receiving objects: 100% (3140/3140), 935.39 KiB | 702.00 KiB/s, done.
Resolving deltas: 100% (1106/1106), done.
按照说明修改_vimrc copy如下文件到_vimrc中(此处从git中做了修改,因为我不需要其他插件只要youcompleteme,当然我的下载路径也是VIMRUNTIME/../bundle)
D:\Program Files\Vim>gvim _vimrc
把下边的东西复制粘贴在最后
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=$VIMRUNTIME/../bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
"Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
"Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
Plugin 'Valloric/YouCompleteMe'
call vundle#end() " required
let g:vundle#bundle_dir=$VIMRUNTIME."/../bundle"
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
color evening
保存重启VIM 或者输入命令source %
再输入命令:PluginInstall就可以看见Vundle已经开始安装Vundle和YouCompleteMe了
耐心等候youcompleteme的安装。
第四步 安装完成MS VC buildtools 和 youcompleteme的源代码后开始编译
D:\Program Files\Vim\bundle\YouCompleteMe>python install.py
可以看到编译过程中有如下一句
ycm_core.vcxproj -> D:\Program Files\Vim\bundle\YouCompleteMe\third_party\ycmd\ycm_core.pyd
把D:\Program Files\Vim\bundle\YouCompleteMe\third_party\ycmd加入到环境变量。也可以把ycm_core.pyd复制到python3.7的执行路径下。因为VIM需要调用ycm_core.pyd
因为youcompleteme需要utf-8编码
在D:\Program Files\Vim\vim81\ftplugin\python.vim文件最后加上set enc=utf-8
pip3 install future