2021-05-12 14:32:11
Vim安裝YouCompleteMe外掛與Python補全外掛jedi-vim
一、安裝YouCompleteMe
1.安裝vundle外掛
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
2.安裝YouCompleteMe
在.vimrc中新增:
Bundle ‘Valloric/YouCompleteMe’
然後進入vim,輸入:
:BundleInstall
然後坐等安裝……..
結束時有個錯誤,這是正常的,因為ycm需要手工編譯出庫檔案
cd ~/ .vim/bundle/YouCompleteMe && ./install.sh
期間好像有個報錯,提示需要安裝了cmake,根據提示安裝即可.
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
(Required is at least version "2.6")
這個報錯表示沒有安裝python-dev
執行sudo apt-get install python-dev即可。
安裝完成後在.vimrc中新增如下設定
"youcompleteme 預設tab s-tab 和自動補全衝突
"let g:ycm_key_list_select_completion=['<c-n>']
let g:ycm_key_list_select_completion = ['<Down>']
"let g:ycm_key_list_previous_completion=['<c-p>']
let g:ycm_key_list_previous_completion = ['<Up>']
let g:ycm_confirm_extra_conf=0 "關閉載入.ycm_extra_conf.py提示
let g:ycm_collect_identifiers_from_tags_files=1 " 開啟 YCM 基於標籤引擎
let g:ycm_min_num_of_chars_for_completion=2 " 從第2個鍵入字元就開始羅列匹配項
let g:ycm_cache_omnifunc=0 " 禁止快取匹配項,每次都重新生成匹配項
let g:ycm_seed_identifiers_with_syntax=1 " 語法關鍵字補全
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR> "force recomile with syntastic
"nnoremap <leader>lo :lopen<CR> "open locationlist
"nnoremap <leader>lc :lclose<CR> "close locationlist
inoremap <leader><leader> <C-x><C-o>
"在註釋輸入中也能補全
let g:ycm_complete_in_comments = 1
"在字串輸入中也能補全
let g:ycm_complete_in_strings = 1
"注釋和字串中的文字也會被收入補全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
二、安裝jedi外掛
1.安裝jedi-vim
在.vimrc中新增:
Bundle ‘davidhalter/jedi-vim’
然後進入vim執行BundleInstall
2.安裝jedi模組
sudo pip install jedi
安裝完成.
gethub上的設定說明:
Settings
Jedi is by default automatically initialized. If you don’t want that I suggest you disable the auto-initialization in your .vimrc:
let g:jedi#auto_initialization = 0
There are also some VIM options (like completeopt and key defaults) which are automatically initialized, but you can skip this:
let g:jedi#auto_vim_configuration = 0
You can make jedi-vim use tabs when going to a definition etc:
let g:jedi#use_tabs_not_buffers = 1
If you are a person who likes to use VIM-splits, you might want to put this in your .vimrc:
let g:jedi#use_splits_not_buffers = “left”
This options could be “left”, “right”, “top”, “bottom” or “winwidth”. It will decide the direction where the split open.
Jedi automatically starts the completion, if you type a dot, e.g. str., if you don’t want this:
let g:jedi#popup_on_dot = 0
Jedi selects the first line of the completion menu: for a better typing-flow and usually saves one keypress.
let g:jedi#popup_select_first = 0
Jedi displays function call signatures in insert mode in real-time, highlighting the current argument. The call signatures can be displayed as a pop-up in the buffer (set to 1, the default), which has the advantage of being easier to refer to, or in Vim’s command line aligned with the function call (set to 2), which can improve the integrity of Vim’s undo history.
let g:jedi#show_call_signatures = “1”
Here are a few more defaults for actions, read the docs (:help jedi-vim) to get more information. If you set them to “”, they are not assigned.
NOTE: subject to change!
let g:jedi#goto_command = “d”
let g:jedi#goto_assignments_command = “g”
let g:jedi#goto_definitions_command = “”
let g:jedi#documentation_command = “K”
let g:jedi#usages_command = “n”
let g:jedi#completions_command = “”
let g:jedi#rename_command = “r”
Finally, if you don’t want completion, but all the other features, use:
let g:jedi#completions_enabled = 0
更多Vim相關教學見以下內容:
Vim學習指南 http://www.linuxidc.com/Linux/2013-08/89096.htm
快速學會 Vi編輯器 http://www.linuxidc.com/Linux/2013-08/88586.htm
強大的Vim 編輯器 http://www.linuxidc.com/Linux/2013-07/87544.htm
在CentOS 6.2上搭建Vim開發環境 http://www.linuxidc.com/Linux/2013-07/87363.htm
把Vim打造成優秀的C++ IDE http://www.linuxidc.com/Linux/2016-06/132262.htm
Vim技巧分享:C語言設定 http://www.linuxidc.com/Linux/2012-12/77124.htm
Ubuntu中設定Vim的行號 http://www.linuxidc.com/Linux/2012-12/75485.htm
本文永久更新連結地址:http://www.linuxidc.com/Linux/2016-07/133491.htm
相關文章