文章目录
配置vim设置vim C/C++开发环境安装Vundle进行插件管理输入以下命令配置插件安装插件括号和引号匹配自动补全Formatter配置vim
设置vim C/C++开发环境
在~/.vimrc
中输入以下内容
set enc=utf-8set fenc=utf-8set termencoding=utf-8" disable vi compatibility (emulation of old bugs)set nocompatible" use indentation of previous lineset autoindent" use intelligent indentation for Cset smartindent" configure tabwidth and insert spaces instead of tabsset tabstop=4 " tab width is 4 spacesset shiftwidth=4" indent also with 4 spacesset expandtab " expand tabs to spaces" wrap lines at 120 chars. 80 is somewaht antiquated with nowadays displays.set textwidth=120" turn syntax highlighting onset t_Co=256syntax on" colorscheme wombat256" turn line numbers onset number" highlight matching bracesset showmatch" intelligent commentsset comments=sl:/*,mb:\ *,elx:\ */" Install OmniCppComplete like described on /wiki/C++_code_completion" This offers intelligent C++ completion when typing ‘.’ ‘->’ or <C-o>" Load standard tag filesset tags+=~/.vim/tags/cppset tags+=~/.vim/tags/glset tags+=~/.vim/tags/sdlset tags+=~/.vim/tags/qt4" Install DoxygenToolkit from /scripts/script.php?script_id=987let g:DoxygenToolkit_authorName="John Doe <john@>"" Enhanced keyboard mappings"" in normal mode F2 will save the filenmap <F2> :w<CR>" in insert mode F2 will exit insert, save, enters insert againimap <F2> <ESC>:w<CR>i" switch between header/source with F4map <F4> :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp,<CR>" recreate tags file with F5map <F5> :!ctags -R –c++-kinds=+p –fields=+iaS –extra=+q .<CR>" create doxygen commentmap <F6> :Dox<CR>" build using makeprg with <F7>map <F7> :make<CR>" build using makeprg with <S-F7>map <S-F7> :make clean all<CR>" goto definition with F12map <F12> <C-]>" in diff mode we use the spell check keys for mergingif &diff” diff settingsmap <M-Down> ]cmap <M-Up> [cmap <M-Left> domap <M-Right> dpmap <F9> :new<CR>:read !svn diff<CR>:set syntax=diff buftype=nofile<CR>ggelse" spell settings:setlocal spell spelllang=en" set the spellfile - folders must existset spellfile=~/.vim/spellfile.addmap <M-Down> ]smap <M-Up> [sendif
安装Vundle进行插件管理
输入以下命令
git clone /VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
配置插件
把以下命令输入~/.vimrc
的顶部
set nocompatible " be iMproved, requiredfiletype off " required" set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()" alternatively, pass a path where Vundle should install plugins"call vundle#begin('~/some/path/here')" let Vundle manage Vundle, requiredPlugin 'VundleVim/Vundle.vim'" The following are examples of different formats supported." Keep Plugin commands between vundle#begin/end." plugin on GitHub repoPlugin 'tpope/vim-fugitive'" plugin from http://vim-/vim/scripts.html" Plugin 'L9'" Git plugin not hosted on GitHubPlugin 'git:///command-t.git'" git repos on your local machine (i.e. when working on your own plugin)Plugin 'file:///home/gmarik/path/to/plugin'" The sparkup vim script is in a subdirectory of this repo called vim." Pass the path to set the runtimepath properly.Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}" Install L9 and avoid a Naming conflict if you've already installed a" different version somewhere else." Plugin 'ascenator/L9', {'name': 'newL9'}. Plugin 'Raimondi/delimitMate' . Plugin 'Chiel92/vim-autoformat' . Plugin 'ycm-core/YouCompleteMe' Plugin 'flazz/vim-colorschemes' " All of your Plugins must be added before the following linecall vundle#end() " requiredfiletype plugin indent on " required
安装插件
打开vim
然后输入:PluginInstall
命令来安装插件。
vim
下方出现Done
表示安装成功。
括号和引号匹配
可以安装delimitMate
插件处理各种括号和引号匹配的问题。
可以使用Vundle的形式安装。
在~/.vimrc
添加Plugin 'Raimondi/delimitMate'
,然后打开vim
输入:PluginInstall
进行插件安装。
自动补全
对于代码自动补全功能,可以安装YouCompleteMe。
首先输入以下命令
cd ~/.vim/bundlegit clone /ycm-core/YouCompleteMe.git
下载完成后进入YCM目录下
cd ~/.vim/bundle/YouCompleteMe
然后输入以下命令
git submodule --init --recursive
这个过程比较慢,如果初始化不成功,需要手动初始化。
以上过程结束后,需要执行下面的文件
./install.py
安装完毕之后,在~/.vimrc
中添加
Plugin 'ycm-core/YouCompleteMe'
打开vim
输入:PluginInstall
安装插件。
Formatter
在vim
中提供格式化功能。
在~/.vimrc
中输入
Plugin 'Chiel92/vim-autoformat'
然后打开vim
,输入:PluinInstall
进行插件的安装。
vim-autoformat
只是一个格式化框架,还需要安装其他工具才可以格式化代码。其他工具点击这里,打开网站进行安装即可。
如安装astyle
,点击。
输入
$ sudo apt-get install astyle
网站上有一些对应的配置。配置。
在~/.vimrc
中输入
let g:formatdef_harttle = '"astyle --style=kr --pad-oper -xg -c -N"'let g:formatters_cpp = ['harttle']noremap <F3> :Autoformat<CR>