一开始一直以为是YCM的锅,唉,经常会怀疑错嫌疑人啊,跟侦探小说一样,得不断推理排除。
最后发现是编译vim 的参数的锅。然后网上一顿瞎操作,并没啥破作用。
首先假设你的python环境是正常的(2.7或/和3.5.1+)
高版本的vim 要3.5+,按实际需要配。
#
cd ~/.vim/bundle/
git clone https://github.com/ycm-core/YouCompleteMe.git
cd YouCompleteMe
python3 install.py --all
最后会出现
[ 98%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ycm_core.cpp.o
[100%] Linking CXX shared library /home/b/.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so
[100%] Built target ycm_core
好了,这就成功编好了。
如果多了
ERROR: msbuild or xbuild is required to build Omnisharp.
这行错误也没关系,如果你不使用C#的话对你没影响,如果你用的话应该不会缺这库。
注意了:
#在一个你喜欢的目录
git clone https://github.com/vim/vim.git
cd vim
#骚东西来了
./configure --with-features=huge --enable-multibyte --enable-rubyinterp=yes --enable-python3interp=yes --with-python3-config-dir=$(python3-config --configdir) --enable-perlinterp=yes --enable-luainterp=yes --enable-gui=gtk2 --enable-cscope --prefix=/usr/local
#不加-j8也可以,如果你不介意慢点的话
make -j8
sudo make install
#好了,事情就这样成了,快乐玩耍吧
vim fk
要注意的点:
./configure 这里加的参数很重要。点这,敢吗你
不然你打开vim时,会报诸如:
YouCompleteMe unavailable: unable to load Python.
youcompleteme unavailable: requires vim compiled with python (2.7 1 or 3.5 1 support)
等错误,然后你安装的YCM插件并不起作用。原因就一个,你编译vim时给它的参数不对或甚至就没指定,然后你编译好之后,vim运行是要去找python结果找不到,然后你就看到上面的关于python的问题了。
判断vim的环境参数有没设置好的方法:
#在你编译vim的目录,也就是vim/src/
#你make 出来的可执行文件在这,除非你手动指定了一个目录
./vim --version |grep python
如果出现的是下面的这些,那么在linux下应该你的vim是用不了的YCM的。
#这种xxx/dyn 是windows的
vim --version |grep python
+comments +libcall +python/dyn +visual
+conceal +linebreak +python3/dyn +visualextra
#这种-xxxx 表示缺了
vim --version |grep python
+comments +libcall -python +visual
+conceal +linebreak -python3 +visualextra
具体可以参考下面的探索过程。。。。
如果遇到
YouCompleteMe unavailable: No module named 'future'
看这:添加链接描述
添加链接描述
Fixed with the following 2 steps:
git submodule update --init --recursive
Reinstall youcompleteme:
python3 install.py --clang-completer --clangd-completer
如果不行,则先删掉third_party
20122 cd .vim/bundle/YouCompleteMe/
20123 git submodule update --init --recursive
20124 ls
20125 cd third_party/
20126 ls
20127 cd ..
20128 rm -rf third_party/
20129 git submodule update --init --recursive
20130 python3 install.py --all
20131 python3 install.py --clang-completer --clangd-completer
也就是执行两个命令:
~/.vim/bundle/YouCompleteMe (master)$ git submodule update --init --recursive
python3 install.py --all
不重新install.py 则打开vim会出现:
The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library not detected; you need t
o compile YCM before using it. Follow the instructions in the documentation.
想直接解决问题的看上面的正确步骤即可,下面的可忽略。
先过掉python找不到的bug:
编译vim源码:
cd src
./configure
20041 make
20042 ./vim --version |grep python
20043 ./configure --enable-pythoninterp=yes --enable-python3interp=yes support for py2 and py3
20044 make distclean
20045 ./configure --enable-pythoninterp=yes --enable-python3interp=yes support for py2 and py3
20046 make
20047 ./vim --version |grep python
/vim/src (master)$ ./vim --version |grep python
+comments +libcall +python/dyn +visual
+conceal +linebreak +python3/dyn +visualextra
以为好了。。。。然并
[ 92%] Building CXX object ycm/CMakeFiles/ycm_core.dir/LetterNode.cpp.o
[ 93%] Building CXX object ycm/CMakeFiles/ycm_core.dir/PythonSupport.cpp.o
[ 94%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Result.cpp.o
[ 96%] Building CXX object ycm/CMakeFiles/ycm_core.dir/versioning.cpp.o
[ 97%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Utils.cpp.o
[ 98%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ycm_core.cpp.o
[100%] Linking CXX shared library /home/b/.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so
[100%] Built target ycm_core
ERROR: msbuild or xbuild is required to build Omnisharp.
b@k:~/.vim/bundle/YouCompleteMe (master)$ python3 install.py --all
使用以下解决:
~/.vim/bundle/YouCompleteMe (master)$ python3 install.py
这会只默认编译c家族的。(最后验证发现并不是他影响了,无所谓的,反正不用c#,所以没关系的)
我忽略了最后的报错,直接运行:
vim/src (master)$ ./vim hhh
YouCompleteMe unavailable: unable to load Python.
Press ENTER or type command to continue
然后依旧不能运行。
坑爹啊,,,,,试了这么多终于可以了:
20008 ./configure --enable-pythoninterp=yes
20009 make distclean
20010 ./configure --enable-pythoninterp=yes
20011 /configure --enable-pythoninterp=yes --enable-python3interp=yes support for py2 and py3
20012 ./configure --enable-pythoninterp=yes --enable-python3interp=yes support for py2 and py3
20013 make dist
20014 make distclean
20015 ./configure --enable-pythoninterp=yes --enable-python3interp=yes support for py2 and py3
20016 vim --version |grep python
20017 ./configure --enable-pythoninterp=yes --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu/
20018 make distclean
20019 ./configure --enable-pythoninterp=yes --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu/
20020 vim --version |grep python
20021 python3 --version
20022 which python
20023 which python3
20024 ls
20025 ./configure --with-features=huge
20026 --enable-multibyte
20027 --enable-rubyinterp=yes
20028 --enable-pythoninterp=yes
20029 --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu
20030 --enable-python3interp=yes
20031 --with-python3-config-dir=/usr/lib/python3.5/config
20032 --enable-perlinterp=yes
20033 --enable-luainterp=yes
20034 --enable-gui=gtk2
20035 --enable-cscope
20036 vim --version |grep python
20037 ls
20038 cd src/
20039 ls
20040 ./configure
20041 make
20042 ./vim --version |grep python
20043 ./configure --enable-pythoninterp=yes --enable-python3interp=yes support for py2 and py3
20044 make distclean
20045 ./configure --enable-pythoninterp=yes --enable-python3interp=yes support for py2 and py3
20046 make
20047 ./vim --version |grep python
20048 history
20049 ./vim hhh
20050 sbr
20051 ./vim hhh
20052 ./vim --version |grep python
20053 ./vim hhh
20054 sudo make install
20055 vim hhh
20056 sbr
20057 vim hhh
20058 sbr
20059 vim hhh
20060 ./vim --version |grep python
20061 history
20062 ./configure
20063 make distclean
20064 history
20065 make
20066 ./vim --version |grep python
20067 history
20068 ./vim --version |grep python
20069 ./configure --enable-python3interp=yes
20070 ./configure --enable--python3interp=yes --with-python3-config-dir=/usr/lib/python3.5/config
20071 make distclean
20072 ./configure --enable--python3interp=yes --with-python3-config-dir=/usr/lib/python3.5/config
20073 ./vim --version |grep python
20074 make
20075 ./vim --version |grep python
20076 make distclean
20077* ./configure --enable-python3interp=yes --with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/
20078 /configure --enable-pythoninterp=yes --enable-python3interp=yes --with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/
20079 ./configure --enable-pythoninterp=yes --enable-python3interp=yes --with-python3-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/
20080 make -j8
20081 ./vim --version |grep python
20082 ./configure --with-features=huge --enable-multibyte --enable-rubyinterp=yes --enable-python3interp=yes --with-python3-config-dir=$(python3-config --configdir) --enable-perlinterp=yes --enable-luainterp=yes --enable-gui=gtk2 --enable-cscope --prefix=/usr/local
20083 make -j9
20084 ./vim --version |grep python
20085 ./vim hhh