安裝vim
sudo add-apt-repository ppa:jonathonf/vim
sudo apt-get update
sudo apt-get install vim
執行上述三條命令,能夠將 vim 升級到最新的 8.1 版本,後面有幾個插件是支持8.1版本的 vim 的。javascript
在根目錄下創建 .vimrc 文件 和 .vim 目錄php
在 .vim 目錄下創建 bundle 目錄。html
vimrc的配置主要是依賴於Vundle.vim
插件管理
java
在 .vim/bundle 目錄下使用以下命令:python
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
c++
在 .vimrc 中輸入一下內容,而後就是在 Plugin 'VundleVim/Vundle.vim' 中添加你本身須要的插件了,按照 Plugin 'github 上的插件名' 添加本身須要的插件git
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
寫完 .vimrc後,進行插件安裝:github
Launch vim
and run :PluginInstall
typescript
運行以上命令後,插件自動安裝。vim
經過 Vundle 安裝此插件
安裝環境:
sudo apt-get install build-essential cmake
sudo apt-get install python-dev python3-dev
雖然安裝了 python2.7,可是當前版本建議用 python3,能夠切換版本:
當前系統中安裝了3個版本的 python(綠色的,藍色的軟連接),使用 update-alternatives 命令安裝版本:
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2 update-alternatives --install /usr/bin/python python /usr/bin/python3.6m 3
添加以後,切換版本:
1 update-alternatives --config python
llvm 加 clang 安裝:
從 http://releases.llvm.org/download.html 網站上下載 llvm 加 clang 的二進制文件,若沒有對應系統版本的二進制文件,請自行編譯安裝:
下載下來後,解壓,進入解壓後文件的根目錄,執行命令:
cp -R * /usr/local
即安裝完畢。
如果 vundle 沒有安裝成功此插件,請自行在 bundle 目錄下 git clone 此插件,而後在此插件的根目錄下運行以下命令:
git submodule update --init --recursive
退回到用戶根目錄下:
$ mkdir ~/.ycm_build
$ cd ~/.ycm_build
執行命令
1 cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=/usr/local . -DUSE_PYTHON2=OFF ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
運行完畢後,執行命令:
1 cmake --build . --target ycm_core --config Release
運行完畢後,會在 ~/.vim/bundle/YouCompleteMe/third_party/ycmd 目錄下生成一個 .ycm_extra_conf.py 的隱藏文件,後期配置 vimrc 須要用到,同時也會須要編輯此文件。
執行命令 echo | clang -v -E -x c++ -
能夠查看到本身須要添加的庫:
將目錄添加進 flags 數組的末尾,按照裏面的 -isystem + 頭文件目錄格式填寫便可。同事要註釋掉下面的內容:
添加以下命令:
1 " ----------------------------------------------------------------------------------------------------------------------- 2 " YouCompleteMe 3 Plugin 'Valloric/YouCompleteMe' 4 let g:ycm_server_python_interpreter='/usr/bin/python' 5 let g:ycm_error_symbol = '>>' 6 let g:ycm_warning_symbol = '>*' 7 let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py' "配置全局路徑 8 let g:ycm_collect_identifiers_from_tags_files=1 " 開啓 YCM 基於標籤引擎 9 let g:ycm_min_num_of_chars_for_completion=2 "從第2個鍵入字符就開始羅列匹配項 10 let g:ycm_cache_omnifunc=0 "禁止緩存匹配項,每次都從新生成匹配項 11 let g:ycm_seed_identifiers_with_syntax=1 "語法關鍵字補全 12 let g:ycm_complete_in_comments = 1 "在註釋輸入中也能補全 13 let g:ycm_complete_in_strings = 1 "在字符串輸入中也能補全 14 " 註釋和字符串中的文字也會被收入補全 15 let g:ycm_collect_identifiers_from_comments_and_strings = 0 16 let g:clang_user_options='|| exit 0' 17 set completeopt=longest,menu " 讓Vim的補全菜單行爲與通常IDE一致(參考VimTip1228) 18 autocmd InsertLeave * if pumvisible() == 0|pclose|endif " 離開插入模式後自動關閉預覽窗口 19 let g:ycm_confirm_extra_conf = 0 "每次直接加載該文件,不提示是否要加載 20 let g:ycm_semantic_triggers = { 21 \ 'c' : ['->', '.', 're!w{2}'], 22 \ 'objc' : ['->', '.', 're!\[[_a-zA-Z]+\w*\s', 're!^\s*[^\W\d]\w*\s', 23 \ 're!\[.*\]\s'], 24 \ 'ocaml' : ['.', '#'], 25 \ 'cpp,objcpp' : ['->', '.', '::'], 26 \ 'perl' : ['->'], 27 \ 'php' : ['->', '::'], 28 \ 'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go' : ['.'], 29 \ 'ruby' : ['.', '::'], 30 \ 'lua' : ['.', ':'], 31 \ 'erlang' : [':'], 32 \ } 33 nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR> 34 nnoremap <leader>gf :YcmCompleter GoToDefinition<CR> 35 nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
terminal 插件是用於在 vim 中開一個 terminal 窗口,供操做 bash 命令。能夠在 vim 中使用 :terminal 命令打開此窗口。
不過有開源的輔助插件可使用。
在.vimrc 中的 vundle 結構中添加:
1 Plugin 'PangPangPangPangPang/vim-terminal' 2 map <silent> <F12> :VSTerminalToggle<cr> 3 if has('nvim') 4 tnoremap <F12> <C-\><C-n> :VSTerminalToggle<cr> 5 tnoremap <C-w> <C-\><C-n><C-w> 6 else 7 tmap <silent> <F12> <c-w>:VSTerminalToggle<cr> 8 endif 9 let g:vs_terminal_custom_height = 50 10 let g:vs_terminal_custom_pos = 'bottom'
運行 PluginInstall 安裝插件。
效果:
要退出終端,選擇終端,在終端執行 exit,而後 :q 便可
termdebug 是 vim 8.0 之後提供的自帶的新插件,能夠在 vim 窗口實現之前 vimgdb 的調試功能,相比較 vimgdb ,感受功能更強大。
此插件必需要安裝 terminal,在 vim 窗口運行:echo has('terminal') ,若是返回值是 1 ,則當前系統中有 terminal。
termdebug 插件全稱便是 terminal debug Plugin,用於用 gdb 調試一個程序而且可在 vim 窗口中觀察。
要想啓動此插件,首先在 vim 中運行命令:packadd termdebug
對本身編譯出來的二進制文件,注意 vim 打開的程序的源碼目錄必須是根目錄,若是二進制文件爲 hello ,運行:Termdebug hello
此時會打開另外兩個窗口:
咱們既能夠在 GDB 窗口中調試,也能夠在源碼窗口中調試。
更多的命令就須要查閱官方文檔了