首先YCM项目内有许多子模块,然而由于国内的围墙问题,所以下载github上的东西会很慢,
解决方法一,去gitee上找对应的仓库
解决方法二,github的解决方法
首先需要装很多依赖(应该只需要python3.6、vim8.1以上)
不过我把这个链接的依赖全部装了一遍。
附上我看的两个最主要的:
vim升级
python3升级
这里python3升级的时候有一步是这样的(编译),./configure --prefix=/usr/local/python38
最好加上--enable-shared
的选项,变成这样
./configure --enable-shared --prefix=/usr/local/python38
这是因为后面编译YCM的时候,没有python动态库的话会报错。而且这个动态链接库的位置还需要放对
有四个,三个动态库,一个静态库
反正我是全部复制到了/usr/lib/x86_64-linux-gnu
这个目录下。
这些东西全部装完后,就可以到YCM的目录下进行编译了
提前说明一下我的YCM是现通过vim-plug装的,装完后需要去YCM目录下(.vim/plugged/YouCompleteMe
)编译,
这里我遇到了最坑的事情,就是当我执行python3 install.py的时候,总是卡在
这里,我折腾了很久,期间还把ubuntu自带的python3卸载了,这是一件悲惨的事情,一开始我以为鞋在了只需要apt-get安装回来就没事了,实际上并不是这样,python3被卸载以后,用apt装软件会出现各种问题,
大概就是这样,实际上 这个问题的解决只需要将
每次提示的这个文件删掉就好了,删文件这个事情需要重复个大概三四次,也就是需要删除三四个文件,具体的文件路径按照他的提示找就行了。
好了,回到正题,卡在那里很久怎么办,等就行了,它不是卡了,是我的机器太垃圾了,所以他的速度很慢。
编译完成后,vim打开文件会看到一行提示,大概是这样的一串
YouCompleteMe unvailable: xxx undefined symble xxx
最终终于找到解决办法,参见这个链接
问题源自Vim,验证方法很简单。从上述报错信息可知问题源自模块socket
,先打开Python,执行import socket
无报错,说明与Python无关;再打开vim,进入命令行模式,执行
:python3 import socket
立即出现上述报错信息,说明问题出自Vim,与YCM无关。解决方法也很简单,按上述解决办法里提示的,在终端,先执行
export LDFLAGS="-rdynamic"
然后重新编译安装Vim即可。
这个是因为安装的时候缺少了指令--clang-completer
以及下面这个文件放置位置问题,并且放置的位置需要在.vimrc
中指定,
python3 install.py --clang-completer
但是用这个命令安装的是,我又遇到问题了,
-- Downloading libclang 12.0.0 from https://github.com/ycm core/llvm/releases/download/12.0.0/libclang-12.0.0-x86_64-unknown-linux-gnu.tar.bz2
CMake Error at ycm/CMakeLists.txt:107 (file):
file DOWNLOAD HASH mismatch
for file: [/root/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/../clang_archives/libclang-12.0.0-x86_64-unknown-linux-gnu.tar.bz2]
expected hash: [dc7b08d63fcf504fdbcfc5b96c446beee8ee79dc96e8d315666b20030c41e29a]
actual hash: [e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855]
status: [35;"SSL connect error"]
CMake Error at ycm/CMakeLists.txt:123 (message):
Cannot find path to libclang in prebuilt binaries
-- Configuring incomplete, errors occurred!
See also "/tmp/ycm_build_nuqhiw48/CMakeFiles/CMakeOutput.log".
See also "/tmp/ycm_build_nuqhiw48/CMakeFiles/CMakeError.log".
ERROR: the build failed.
NOTE: it is *highly* unlikely that this is a bug but rather
that this is a problem with the configuration of your system
or a missing dependency. Please carefully read CONTRIBUTING.md
and if you're sure that it is a bug, please raise an issue on the
issue tracker, including the entire output of this script
and the invocation line used to run it.
反正就是有一个叫libclang-12.0.0-x86_64-unknown-linux-gnu.tar.bz2
的文件下不下来。
这个时候我们只需要手动下载就好了,问题就在于复制上面报错的时候显示的链接无法访问,所以我们需要用下面这个链接,只需要把你要下载的版本对应的改一下就好了。
https://github.com/ycm-core/llvm/releases/download/12.0.0/libclang-12.0.0-x86_64-unknown-linux-gnu.tar.bz2
然后把下载好的文件放进报错提示的目录下面,注意,该目录下面已经有一个同名的文件,但是文件大小为空,我们需要把该文件重命名成别的名字就行。
然后在编译,问题就解决了。
let mapleader=" "
set autoindent
"set shiftwidth=4
"set mouse=a
set number
set cindent
"set tabstop=4
set viminfo='1000
set nocompatible
filetype on
filetype indent on
filetype plugin on
filetype plugin indent on
set mouse=a
set encoding=utf-8
let &t_ut=''
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set list
set listchars=tab:鈻竆 ,trail:鈻?set scrolloff=5
set tw=0
set indentexpr=
set backspace=indent,eol,start
set foldmethod=indent
set foldlevel=99
let &t_SI = "\]50;CursorShape=1\x7"
let &t_SR = "\]50;CursorShape=2\x7"
let &t_EI = "\]50;CursorShape=0\x7"
set laststatus=2
set autochdir
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
set wildmenu "鍛戒护琛岋紝杈撳叆鍛戒护涓嶅叏鍔熻兘"
set cursorline "鍏夋爣鎵€鍦ㄨ鐨勬í绾?
set showcmd "鏄剧ず鍛戒护"
exec "nohlsearch"
set hlsearch "楂樹寒鎼滄墍"
set incsearch "杈规悳杈归珮浜?
"鏇存敼閿洏鏄?鏍煎紡 noremap 鐜板湪鐨勯敭 鍘熸潵鐨勯敭"
noremap j h
noremap i k
noremap k j
noremap h i
noremap H I
noremap = n
noremap - N
noremap n =
noremap <LEADER><CR> :nohlsearch<CR>
noremap <LEADER>[ ^
noremap <LEADER>] $
"璁剧疆閿洏鏄犲皠鍒悕,鏍煎紡 map 鍒悕 鍘熷悕"
map s <nop> "<nop> nooperation 浠€涔堥兘涓嶅仛
map S :w<CR>
map Q :q<CR>
map R :source $MYVIMRC<CR>
map sl :set splitright<CR>:vsplit<CR> "鍚戝彸鍒嗗睆"
map sj :set nosplitright<CR>:vsplit<CR> "鍚戝乏鍒嗗睆"
map si :set nosplitbelow<CR>:split<CR> "鍚戜笂鍒嗗睆"
map sk :set splitbelow<CR>:split<CR> "鍚戜笅鍒嗗睆"
map <LEADER>l <C-w>l "鍒嗗睆鏃讹紝鍏夋爣鍚戝彸绐楀彛"
map <LEADER>j <C-w>h "鍒嗗睆鏃讹紝鍏夋爣鍚戝乏绐楀彛"
map <LEADER>i <C-w>k "鍒嗗睆鏃讹紝鍏夋爣鍚戜笂绐楀彛"
map <LEADER>k <C-w>j "鍒嗗睆鏃讹紝鍏夋爣鍚戜笅绐楀彛"
map <LEADER><up> :res +5<CR> "鍒嗗睆鏃讹紝鍒嗛厤绐楀彛澶у皬"
map <LEADER><down> :res -5<CR> "鍒嗗睆鏃讹紝鍒嗛厤绐楀彛澶у皬"
map <LEADER><right> :vertical resize-5<CR> "鍒嗗睆鏃讹紝鍒嗛厤绐楀彛澶у皬"
map <LEADER><left> :vertical resize+5<CR> "鍒嗗睆鏃讹紝鍒嗛厤绐楀彛澶у皬"
map tu :tabe<CR> "鏂板缓鏍囩椤?
map tn :-tabnext<CR> "鏌ョ湅涓婁竴涓爣绛鹃〉"
map ti :+tabnext<CR> "鏌ョ湅涓嬩竴涓爣绛鹃〉"
map sv <C-w>t<C-w>H "姘村钩鍒嗗睆鏃讹紝鍒囨崲涓哄瀭鐩村垎灞?
map sh <C-w>t<C-w>K "鍨傜洿鍒嗗睆鏃讹紝鍒囨崲涓烘按骞冲垎灞?
call plug#begin('~/.vim/plugged')
Plug 'vim-airline/vim-airline'
Plug 'connorholyday/vim-snazzy'
Plug 'https://github.com.cnpmjs.org/dense-analysis/ale.git'
Plug 'https://github.com.cnpmjs.org/Valloric/YouCompleteMe'
call plug#end()
colorscheme snazzy
" " ===
" " === You Complete ME
" " ===
nnoremap gd :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap g/ :YcmCompleter GetDoc<CR>
nnoremap gt :YcmCompleter GetType<CR>
nnoremap gr :YcmCompleter GoToReferences<CR>
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_autoclose_preview_window_after_insertion=1
let g:ycm_use_clangd = 0
let g:ycm_python_interpreter_path = "/usr/local/bin/python3"
let g:ycm_python_binary_path = "/usr/local/bin/python3"
let g:ycm_global_ycm_extra_conf = '~/.vim/plugged/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py' " 浣犵殑鏂囦欢璺緞
let g:ycm_show_diagnostics_ui = 1 " 璇硶妫€鏌ュ紑鍏?
" ===
" === ale
" ===
let b:ale_linters = ['pylint']
let b:ale_fixers = ['autopep8', 'yapf']