安装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 窗口中调试,也能够在源码窗口中调试。
更多的命令就须要查阅官方文档了