Install Youcompleteme and other vim plugin

1.
Download Vundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

2.Edit /etc/vim/vimrc and add below command then execute PluginInstall command in vim


"======================
" Start vundle
"=======================
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()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

"========================================
" Write your plugins here
"========================================
Plugin 'Yggdroot/indentLine'
Plugin 'ntpeters/vim-better-whitespace'
Plugin 'vim-airline/vim-airline'
Plugin 'tpope/vim-fugitive'
Plugin 'chazy/cscope_maps'
Plugin 'vim-scripts/taglist.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'wesleyche/SrcExpl'
Plugin 'wesleyche/Trinity'
Plugin 'majutsushi/tagbar'

"====================================================================
" Run vundle
"====================================================================
" All of your Plugins must be added before the following line
call vundle#end() " required
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

3. Set Plugin hotkey, Add below command to /etc/vim/vimrc

map <silent> <F5> :TlistToggle <cr>
map <silent> <F6> :TlistOpen <cr>

" Open and close the tagbar separately
nmap <F7> :TagbarToggle<CR>

" Open and close the Source Explorer separately
nmap <F8>  :TrinityToggleSourceExplorer<CR>

" Open and close the NERD Tree separately
nmap <F9> :TrinityToggleNERDTree<CR>
nnoremap <silent> <F10> :NERDTree<CR>

4.Install YouCompleteMe and setup plugin 

Method 1: apt-get youcompleteme, stable on ubuntu 18.04/14.04 but it have problem on ubuntu 16.04
apt-get install vim-youcompleteme
apt-get install vim-addon-manager
vam install youcompleteme
 


Method 2: Compile youcompleteme

Add below line to vimrc
Plugin 'Valloric/YouCompleteMe'
open vim and enter :PluginInstall

Because my python version is old so I can't sue the latest YCM version
Enter YouCompleteme Folder and reset git version to old YCM

(1)Older version, clang 10 version, but clang file could not be download from server. The YcmCompleter will be unable to use
git reset 106e9be4c07de01561cdf53a8a79119fec9e9a72
(2)Newer version, clang 15 version. This version works well for me. cmake version 3.14+ is required when building ycm
git reset a08a0b92a9d02fbde075fe130eac7c1914e7f5a1
rm -rf *
git reset --hard
git submodule update --init --recursive

Note: The latest version of YCM is base on clang 16, python 3.8+ is required for building ycm. My Os is not update python version to 3.8+ so I could not use the latest version.

With YCM internal clang
sudo apt install python-dev python3-dev
sudo apt install build-essential cmake
cd ~/.vim/bundle/YouCompleteMe/
sudo python3 install.py --clang-completer

Note : For YCM with clang version 15
python3.7m install.py --clang-completer --cmake-path=/home/yclee/usr/bin/bin/cmake

With system-self clang
curl -SL http://releases.llvm.org/7.0.1/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz | tar -xJC .
cp -ar clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/ /usr/local/
add /usr/local/lib/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/lib to /etc/ld.so.conf.d/clang_for_ycm.conf
sudo vim /etc/ld.so.conf.d/clang_for_ycm.conf
sudo ldconfig
sudo update-alternatives --install /usr/bin/clangd clangd /usr/local/lib/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/bin/clangd 999
sudo update-alternatives --set clangd /usr/local/lib/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/bin/clangd
sudo update-alternatives --config clangd
export LD_LIBRARY_PATH=/usr/local/lib/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-16.04/lib/:$LD_LIBRARY_PATH
python3 install.py --clang-completer --system-libclang

Add below command to /etc/vim/vimrc
let g:ycm_python_binary_path = '/usr/bin/python3.5'
let g:ycm_global_ycm_extra_conf = '/.ycm_extra_conf.py'
let g:ycm_confirm_extra_conf=0
let g:ycm_keep_logfiles = 1
let g:ycm_log_level='debug'
let g:ycm_key_invoke_completion = ''
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_seed_identifiers_with_syntax=1
let g:ycm_complete_in_comments=1
let g:syntastic_cpp_compiler = 'g++'
let g:ycm_clangd_uses_ycmd_caching = 1
let g:ycm_clangd_binary_path = exepath("clangd") #Add this to enable clangd function
let g:ycm_clangd_args = ['-limit-results=0','-I/custom/include_path'] #Add clangd args here, ex include path



Setting parameter 
vim /usr/lib/vim-youcompleteme/ycm_extra_conf.py 

Add this to vimrc
let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'
YcmError message solution:
1.ImportError: libclang.so.7: cannot open shared object file: No such file or directory
Ans: sudo vim /etc/ld.so.conf.d/clang_for_ycm.conf
add ~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/clang/lib/
sudo ldconfig

ycm_extra_conf.py 
 

Trobleshooting
(1) If you encounter "YouCompleteMe unavailable: unable to load Python." issue or "YouCompleteMe unavailable:invalid syntax(vimsupport.py, line 184)" issue.
Please recompile vim 
1. Fetch vim source code

git clone https://github.com/vim/vim.git

2.Compile vim with python3.7
./configure --prefix=/home/yclee/usr \
--with-features=huge \
--enable-multibyte \
--enable-gtk3-check \
--enable-rubyinterp=yes \
--with-python3-command=python3.7m \
--enable-python3interp=yes \
--enable-perlinterp=yes \
--enable-luainterp=yes \
--enable-cscope \
--enable-largefile

make -j32
make install

(2)If you could not fetch
git://github.com/mitsuhiko/flask-sphinx-themes.git correctly

git config --global url."https://".insteadOf git://




沒有留言:

張貼留言

Install KDE Desktop for Ubuntu 24.04

1. Enter following command to install the KDE-plasma sudo apt install kde-plasma-desktop 2. Disable the login screen 2-1. Create default sdd...