vim 打造C++開發環境

vim 打造C++開發環境

文章轉自這裏

安裝pathogen

項目地址: https://github.com/tpope/vim-pathogen

$ mkdir -p ~/.vim/autoload ~/.vim/bundle 
$ curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

~/.vimrc中加入以下內容:

execute pathogen#infect()

安裝auto-pairs

項目地址: https://github.com/jiangmiao/auto-pairs

$ git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs

安裝NERDTree

項目地址: https://github.com/scrooloose/nerdtree

git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle

打開方式:

  1. 在vim命令模式下輸入NEEDTree

  2. ~/.vimrc中設置自定義快捷鍵Ctrl+n

    map <C-n> :NERDTree<CR>
    

安裝MiniBufExplorer

項目地址: http://www.vim.org/scripts/script.php?script_id=159

$ mkdir -p ~/.vim/bundle/minibufexplorer/plugin && wget "http://www.vim.org/scripts/download_script.php?src_id=3640" -O ~/.vim/bundle/minibufexplorer/plugin/minibufexpl.vim

vimrc中加入以下內容:

let g:miniBufExplMaxSize = 2

安裝ctags+taglist+omnicppcomplete

ctags

現在基本上Linux都會自帶,沒有安裝的自行摸索

安裝完成之後在項目根目錄下建立索引語句:

$ ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++

taglist

項目地址: http://www.vim.org/scripts/script.php?script_id=273

$ cd ~/.vim/bundle && wget "http://www.vim.org/scripts/download_script.php?src_id=19574" -O taglist.zip && unzip taglist.zip -d taglist

打開~/.vimrc進行配置:

    let Tlist_Show_One_File=1    " 只展示一個文件的taglist
    let Tlist_Exit_OnlyWindow=1  " 當taglist是最後以個窗口時自動退出
    let Tlist_Use_Right_Window=1 " 在右邊顯示taglist窗口
    let Tlist_Sort_Type="name"   " tag按名字排序

OmniCppComplete

項目地址: http://www.vim.org/scripts/script.php?script_id=1520

$ cd ~/.vim/bundle && wget "http://www.vim.org/scripts/download_script.php?src_id=7722" -O omnicppcomplete.zip && unzip omnicppcomplete.zip -d omnicppcomplete

打開~/.vimrc進行配置:

filetype plugin indent on
set completeopt=longest,menu
let OmniCpp_NamespaceSearch = 2     " search namespaces in the current buffer   and in included files
let OmniCpp_ShowPrototypeInAbbr = 1 " 顯示函數參數列表
let OmniCpp_MayCompleteScope = 1    " 輸入 :: 後自動補全
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]

由於是依賴ctags使用前需要更新索引(項目根目錄下使用)

$ ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++

對STL模板庫的補全:

$ mkdir -p ~/.vim/tags && cd ~/.vim/tags && wget "http://www.vim.org/scripts/download_script.php?src_id=9178" -O - | tar jxvf -

打開~/.vimrc進行配置:

set tags+=~/.vim/tags/cpp_src/tags

SuperTab

項目地址: https://github.com/ervandew/supertab

$ cd ~/.vim/bundle && git clone https://github.com/ervandew/supertab.git

最終配置文件

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
" debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
set nocompatible

" Vim5 and later versions support syntax highlighting. Uncommenting the
" following enables syntax highlighting by default.
if has("syntax")
syntax on " 語法高亮
endif
colorscheme ron " elflord ron peachpuff default 設置配色方案,vim自帶的配色方案保存在/usr/share/vim/vim72/colors目錄下

" detect file type
filetype on
filetype plugin on

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"have Vim load indentation rules and plugins according to the detected filetype
filetype plugin indent on
endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.

"set ignorecase " 搜索模式裏忽略大小寫

"set smartcase " 如果搜索模式包含大寫字符,不使用 'ignorecase' 選項。只有在輸入搜索模式並且打開 'ignorecase' 選項時纔會使用。

set autowrite " 自動把內容寫回文件: 如果文件被修改過,在每個:next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、CTRL-] 和 CTRL-^命令時進行;用 :buffer、CTRL-O、CTRL-I、'{A-Z0-9} 或 `{A-Z0-9} 命令轉到別的文件時亦然。

set autoindent " 設置自動對齊(縮進):即每行的縮進值與上一行相等;使用 noautoindent 取消設置

"set smartindent " 智能對齊方式

set tabstop=4 " 設置製表符(tab鍵)的寬度

set softtabstop=4 " 設置軟製表符的寬度

set shiftwidth=4 " (自動) 縮進使用的4個空格

set cindent " 使用 C/C++ 語言的自動縮進方式

set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "設置C/C++語言的具體縮進方式

"set backspace=2 " 設置退格鍵可用

set showmatch " 設置匹配模式,顯示匹配的括號

set linebreak " 整詞換行

set whichwrap=b,s,<,>,[,] " 光標從行首和行末時可以跳到另一行去

"set hidden " Hide buffers when they are abandoned

set mouse=a " Enable mouse usage (all modes) "使用鼠標

set number " Enable line number "顯示行號

"set previewwindow " 標識預覽窗口 set history=50 " set command history to 50 "歷史記錄50條 "--狀態行設置-- set laststatus=2 " 總顯示最後一個窗口的狀態行;設爲1則窗口數多於一個的時候顯示最後一個窗口的狀態行;0不顯示最後一個窗口的狀態行 set ruler " 標尺,用於顯示光標位置的行號和列號,逗號分隔。每個窗口都有自己的標尺。如果窗口有狀態行,標尺在那裏顯示。否則,它顯示在屏幕的最後一行上。 "--命令行設置-- set showcmd " 命令行顯示輸入的命令 set showmode " 命令行顯示vim當前模式 "--find setting-- set incsearch " 輸入字符串就顯示匹配點 set hlsearch


" 插件相關
execute pathogen#infect()


map <C-n> :NERDTree<CR>

let g:miniBufExplMaxSize = 2

let Tlist_Show_One_File=1    " 只展示一個文件的taglist
let Tlist_Exit_OnlyWindow=1  " 當taglist是最後以個窗口時自動退出
let Tlist_Use_Right_Window=1 " 在右邊顯示taglist窗口
let Tlist_Sort_Type="name"   " tag按名字排序

filetype plugin indent on
set completeopt=longest,menu
let OmniCpp_NamespaceSearch = 2     " search namespaces in the current buffer   and in included files
let OmniCpp_ShowPrototypeInAbbr = 1 " 顯示函數參數列表
let OmniCpp_MayCompleteScope = 1    " 輸入 :: 後自動補全
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]

set tags+=~/.vim/tags/cpp_src/tags

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章