基本配置:php
et wildmenu
「加強模式中的命令行自動完成操做
set foldmethod=manual
「設定摺疊方式爲手動
set cin
「實現C程序的縮進
set sta
「插入<tab>時使用’shiftwidth’
set backspace=2
「指明在插入模式下可使用<BS>刪除光標前面的字符
syntax enable
「設置高亮關鍵字顯示
set nocompatible
「去掉討厭的有關vi一致性模式,避免之前版本的一些bug和侷限
set number
「顯示行號
filetype on
「檢測文件的類型
set history=1000
「」記錄歷史的行數
set background=dark
「背景使用黑色
set autoindent
set smartindent
「上面兩行在進行編寫代碼時,在格式對起上頗有用;
「第一行,vim使用自動對起,也就是把當前行的對起格式應用到下一行;
「第二行,依據上面的對起格式,智能的選擇對起方式,對於相似C語言編寫上頗有用
「第一行設置tab鍵爲4個空格,第二行設置當行之間交錯時使用4個空格
set tabstop=4
set shiftwidth=4
set showmatch
「設置匹配模式,相似當輸入一個左括號時會匹配相應的那個右括號
set ruler
「在編輯過程當中,在右下角顯示光標位置的狀態行
set incsearch
「查詢時很是方便,如要查找book單詞,當輸入到/b時,會自動找到第一
「個b開頭的單詞,當輸入到/bo時,會自動找到第一個bo開頭的單詞,依
「次類推,進行查找時,使用此設置會快速找到答案,當你找要匹配的單詞
「時,別忘記回車。
set enc=utf-8
「設置編碼爲中文
set winaltkeys=no
「Alt組合鍵不映射到菜單上
set laststatus=2
「老是出現狀態欄
set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P>
「設置狀態欄
set hidden
「設置隱藏已修改buffer
html
autocmd FileType python setlocal et sta sw=4 sts=4java
中文幫助手冊的安裝python
這個看我的須要,下載地址:http://vimcdoc.sourceforge.net/c++
$tar xvf vimcdoc-1.7.0.tar.gz
$ cd vimcdoc-1.7.0/
shell
$ ./vimcdoc.sh -ivim
在一堆done後完成。在~/.vimrc里加上set helplang=cn 這句話標明幫助文檔爲中文。在vim中」:help」後就能看到效果。瀏覽器
1.代碼快速編輯和編譯運行:C-support,Bash-supportbash
C-support下載安裝:app
下載:http://www.vim.org/scripts/script.php?script_id=213
安裝:將下載的文件解壓放到~/.vim目錄中
Bash-support下載安裝:
下載:http://www.vim.org/scripts/download_script.php?src_id=16019
安裝:將下載文件解壓放到~/.vim目錄中
使用方法:
2.閱讀源代碼:Ctags+Tag List +Win Manger+Cscope
這三個分別是生成標籤、列出標籤(使用ctags)、列出文件、代碼跳轉。
下載安裝:
下載安裝Exuberant Ctags :sudo apt-get install exuberant-ctags
(咱們安裝ctags可是並不直接使用它做爲代碼跳轉工具,而是使用cscope)
Teg List下載:http://www.vim.org/scripts/download_script.php?src_id=7701
安裝:解壓到home目錄下的.vim子目錄中。
WinManager(調整窗口布局)下載:http://www.vim.org/scripts/download_script.php?src_id=754
安裝:解壓到home目錄下的.vim子目錄中。
下載安裝cscope:sudo apt-get install cscope
配置:
進入$HOME/.vim/doc打開 Vim 運行 「:helptags .」 這是要保證taglist幫助能夠正常使用。
而後爲後邊配置自動補全創建系統tags:(具體爲何採用這樣的參數請參考ctags命令行幫助)
ctags -R -f ~/.vim/systags –c-kinds=+p –c++-kinds=+px –fields=+iaS –extra=+q –python-kinds=-i /usr/include /usr/local/include
隨後在vimrc中添加以下幾行:
「禁止自動改變當前Vim窗口的大小
let Tlist_Inc_Winwidth=0
「把方法列表放在屏幕的右側
let Tlist_Use_Right_Window=1
「讓當前不被編輯的文件的方法列表自動摺疊起來, 這樣能夠節約一些屏幕空間
let Tlist_File_Fold_Auto_Close=1
「映射F3爲功能鍵調出winmanager的文件瀏覽器
「映射雙擊F3調出Taglist的符號瀏覽器
「let g:winManagerWindowLayout=’FileExplorer|TagList’ 「你要是喜歡這種佈局能夠註釋掉這一行
map <F3> :WMToggle<cr>
map <F3><F3> :TlistToggle<cr>
「將系統已經生成的tags導入
set tags+=~/.vim/systags
「映射F10爲添加cscope和ctags
map <F10> :call Do_CsTag()<CR>
map <F10><F10> :call Add_CsTag()<CR>
nmap <C-\>s :cs find s <C-R>=expand(「<cword>」)<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand(「<cword>」)<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand(「<cword>」)<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand(「<cword>」)<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand(「<cword>」)<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand(「<cfile>」)<CR><CR>
nmap <C-\>i :cs find i ^<C-R>=expand(「<cfile>」)<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand(「<cword>」)<CR><CR>
function Do_CsTag()
silent! execute 「!ctags -R ‘.’」
if(executable(‘cscope’) && has(「cscope」) )
silent! execute 「!find -L `pwd` -name ‘*.h’ -o -name ‘*.c’ -o -name ‘*.cpp’ -o -name ‘*.java’ -o -name ‘*.cs’ -o -name ‘*.cxx’ -o -name ‘*.hxx’> cscope.files -o -name ‘*.hpp’ -o -name ‘*.py’」 endif
silent! execute 「!cscope -bq」
silent! execute 「call Add_CsTag()」
endf
function Add_CsTag()
if filereadable(「cscope.out」)
execute 「cs add cscope.out」
execute 「set tags+=./tags」
endif
endf
silent! execute 「call Add_CsTag()」
使用方法:
i: 查找包含本文件的文件
<CR> 跳到光標下tag所定義的位置,用鼠標雙擊此tag功能也同樣
o 在一個新打開的窗口中顯示光標下tag
<Space> 顯示光標下tag的原型定義
u 更新taglist窗口中的tag
s 更改排序方式,在按名字排序和按出現順序排序間切換
x taglist窗口放大和縮小,方便查看較長的tag
+ 打開一個摺疊,同zo
- 將tag摺疊起來,同zc
* 打開全部的摺疊,同zR
= 將全部tag摺疊起來,同zM
[[ 跳到前一個文件
]] 跳到後一個文件
q 關閉taglist窗口
<F1> 顯示幫助
3.同名頭文件和源文件切換:A
下載安裝:http://www.vim.org/scripts/download_script.php?src_id=7218,將a.vim 放到 ~/.vim/plugin 中。
在.vimrc中添加:map <F11> :A<cr>
4.代碼塊和經常使用語句模板自動補全:code_complete
下載安裝:http://www.vim.org/scripts/download_script.php?src_id=10778 ,放到 ~/.vim/plugin 中。
把插件文件中的tab都改成C-b防止與後來咱們要安裝的supertab衝突。
另外,這個是基於ctags的,因此要生成或加載tags,參見2)部分。
將下邊這一段加入到template段中以添加bash模板補全功能
「Bash Templates
「Bash Structure by warmbupt@gmail.com
let g:template['sh'] = {}
let g:template['sh']['sif'] = 「if 「.g:rs.」…」.g:re.」 ; then/」.g:rs.」…」.g:re.」/fi」
let g:template['sh']['sife'] = 「if 「.g:rs.」…」.g:re.」 ; then/」.g:rs.」…」.g:re.」/else/」.g:rs.」…」.
/g:re.」/fi」
let g:template['sh']['scase'] = 「case 「.g:rs.」…」.g:re.」 in/」.g:rs.」…」.g:re.」)//」 .g:rs.」…」.g:re.」;;//」.
/g:rs.」…」.g:re.」)//」 .g:rs.」…」.g:re.」;;///esac/」
let g:template['sh']['swhile'] = 「while 「.g:rs.」…」.g:re.」 /do/」.g:rs.」…」.g:re.」/done」
let g:template['sh']['suntil'] = 「until 「.g:rs.」…」.g:re.」 /do/」.g:rs.」…」.g:re.」/done」
let g:template['sh']['sfor'] = 「for 「.g:rs.」…」.g:re.」 in 」 .g:rs.」…」.g:re.」/do/」.g:rs.」…」.g:re.」/done」
let g:template['sh']['sselect'] = 「select 「.g:rs.」…」.g:re.」 in 」 .g:rs.」…」.g:re.」/do/」.g:rs.」…」.g:re.」/done」
使用:在輸入函數時能夠快速輸入是安裝這個插件的主要目的。好比,輸入main,而後Crtl+b就能夠看到效果了。對於函數,在輸入strlen(後按C-b,會補全參數,而後再按C-b就能夠一個個填寫參數了。
具體哪些能夠補全以下:
5.代碼補全:supertab+snipMate+omnicppcomplete
下載地址:
http://www.vim.org/scripts/download_script.php?src_id=16104
http://www.vim.org/scripts/download_script.php?src_id=16345
安裝:用vim打開supertab.vba,而後使用:so % 進行安裝。後二者直接解壓在.vim目錄裏便可。
設置:進入vim
:helptags ~/.vim/doc
而且在~/.vim/snippets/python.snippets中添加以下信息:
snippet header
#!/usr/bin/env python
「」"
File: `Filename(‘$1.py’, ‘foo.py’)`
Author: gnuhpc
Company: CMBC
Date: `strftime(「%Y-%m-%d %T %Z」)`
Description: ${1}
「」"
6.原型提示:echofunc
下載安裝:http://www.vim.org/scripts/download_script.php?src_id=15953,而後放到plugin目錄裏。
而後在.vimrc中設置:
let g:EchoFuncKeyNext=’<C-n>’
let g:EchoFuncKeyPrev=’<C-p>’
7.C/STL/Python Doc提示:CRefVim 、stlrefvim 、Pyref
下載安裝:
http://www.vim.org/scripts/download_script.php?src_id=3666
http://www.vim.org/scripts/download_script.php?src_id=9160
http://www.vim.org/scripts/download_script.php?src_id=14576
解壓後將crefvim目錄裏的全部目錄都複製到.vim/下,其他的在.vim目錄解壓便可。
而後進入vim後」 :helptags ~/.vim/doc」
設置:
打開plugin/stlrefvim.vim中將’tr’改成’cr’,這個是爲了好記憶。
把plugin/pyref.vim移動到ftplugin中,這樣只針對python文件的插件。
在.vimrc中添加:let g:pyref_mapping = ‘K’
使用:
8.簡單註釋:comments
下載安裝:http://www.vim.org/scripts/download_script.php?src_id=9801,放到plugin目錄中。這個插件支持不少語言。
9.代碼格式整理:astyle
下載安裝:$sudo apt-get install astyle
配置:
在vimrc中寫入:
「定義源代碼格式化
map <F12> :call FormartSrc()<CR>
「定義FormartSrc()
func FormartSrc()
exec 「w」
if &filetype == ‘c’
exec 「!astyle % –style=ansi –suffix=none %」
exec 「e! %」
elseif &filetype == ‘cpp’
「exec 「!astyle % –style=ansi –suffix=none %」
「exec 「e! %」
elseif &filetype == ‘perl’
exec 「!astyle –style=gnu –suffix=none %」
exec 「e! %」
elseif &filetype == ‘py’
exec 「!astyle –style=gnu –suffix=none %」
exec 「e! %」
elseif &filetype == ‘java’
exec 「!astyle –style=java –suffix=none %」
exec 「e! %」
elseif &filetype == ‘jsp’
exec 「!astyle –style=gnu –suffix=none %」
exec 「e! %」
elseif &filetype == ‘xml’
exec 「!astyle –style=gnu –suffix=none %」
exec 「e! %」
elseif &filetype == ‘html’
exec 「!astyle –style=gnu –suffix=none %」
exec 「e! %」
elseif &filetype == ‘htm’
exec 「!astyle –style=gnu –suffix=none %」
exec 「e! %」
endif
endfunc
「結束定義FormartSrc
10.多tab支持:NERD_tree
下載安裝:http://www.vim.org/scripts/download_script.php?src_id=11834,解壓到.vim目錄便可
設置:
「設置tab的快捷鍵
「Shift+t爲新建一個標籤,按兩次Shirt+t爲跳轉標籤
map <S-t> :tabnew .<CR>
map <S-t><S-t> <ESC>:tabnext<CR>
11. Python自動補全支持:Pydiction
下載安裝:http://www.vim.org/scripts/download_script.php?src_id=11062 解壓放到~/.vim/after/ftplugin/ 路徑下
將complete-dict文件放到~/.vim/tools/pydiction/目錄中。
配置:
「pydiction 1.2 python auto complete
let g:pydiction_location = ‘~/.vim/tools/pydiction/complete-dict’
let g:pydiction_menu_height = 20
12.自動檢查Python語法:pyflakes-vim
下載安裝:pyflakes-vim.zip,在~/.vim/目錄下解壓。
13. Python經常使用功能:python_fn.vim
下載安裝:python_fn.vim, 放到~/.vim/ftplugin/python中便可。
14. Python代碼自動摺疊:Efficient python folding
下載安裝:python_editing.vim,放在~/.vim/ftplugin/python便可。
15.代碼文檔化工具:Doxygen
下載安裝:DoxygenToolkit.vim,放到~/.vim/plugin
安裝doxygen:sudo apt-get install doxygen
配置:.vimrc中添加,其中我的信息能夠本身修改
map <F4>a
oxAuthor<CR>
map <F4>fox<CR>
map <F4>boxBlock<CR>
map <F4>loxLic<CR>
map <F4>c odocClass<C-B>
map <F4>m odocMember<C-B>
let g:DoxygenToolkit_authorName=」pchuang, http://blog.csdn.net」
let s:licenseTag = 「Copyright(C)\<enter>」
let s:licenseTag = s:licenseTag . 「For free\<enter>」
let s:licenseTag = s:licenseTag . 「All right reserved\<enter>」
let g:DoxygenToolkit_licenseTag = s:licenseTag
let g:DoxygenToolkit_briefTag_funcName=」yes」
let g:doxygen_enhanced_color=1
使用:(須要安裝doxygen)
16.配置一鍵編譯調試
在.vimrc中設置:
map <F8> :w<CR>:call CompileRun()<CR>
map <F8><F8> :w<CR>:call Debug()<CR>func CompileRun()
exec 「w」
if &filetype == ‘c’
exec 「!gcc % -g -o %<」
exec 「!.\/%<」
elseif &filetype ==’cpp’
exec 「!g++ % -g -o %<」
exec 「!.\/%<」
elseif &filetype == ‘python’
exec 「!python %」
endif
endfuncfunc Debug()
exec 「w」
if &filetype == ‘c’
exec 「!rm %<」
exec 「!gcc % -g -o %<」
exec 「!gdb %<」
elseif &filetype == ‘cpp’
exec 「!rm %<」
exec 「!g++ % -g -o %<」
exec 「!gdb %<」
exec 「!rm %<.class」
elseif &filetype == ‘java’
exec 「!javac %」
exec 「!jdb %<」
elseif &filetype == ‘python’
exec 「!pdb %」
endif
endfunc
17.shell腳本自動加上執行權限
在.vimrc中配置:
function ModeChange()
if getline(1) =~ 「^#!」
if getline(1) =~ 「/bin/」
silent !chmod a+x <afile>
endif
endif
endfunction
au BufWritePost * call ModeChange()
18.從上次退出時編輯的位置繼續編輯
在.vimrc中配置:
autocmd BufReadPost *
\ if line(「‘\」") > 0 && line (「‘\」") <= line(「$」) |
\ exe 「normal g’\」" |
\ endif
19.配置括號自動添加
在.vimrc中配置:
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(‘)’)<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair(‘}’)<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(‘]’)<CR>
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair(‘>’)<CR>
function ClosePair(char)
if getline(‘.’)[col('.') - 1] == a:char
return 「\<Right>」
else
return a:char
endif
endf
20.添加一些快捷鍵:
在.vimrc中添加:
map <F5> :w<CR>:make<CR>
map <F5><F5> :make clean<CR>
map <F6> :cw<CR>
map <F6><F6> :ccl<CR>
map <F7> :cn<CR>
map <F7><F7> :cp<CR>map <S-o> o<ESC><CR>
map <C-a> ggVG
map <S-q><S-q> :q!<CR>:q!<CR>:q!<CR>
map <C-H> :L1,L2s/src/tar/g
map <S-F12> <ESC>I//<ESC><CR>
map! <S-F12> <ESC>I//<ESC><CR>
map <S-F12><S-F12> 02x<ESC><CR>
map! <S-F12><S-F12> <ESC>02x<ESC><CR>
map <F12> <ESC>$a//
map! <F12> <ESC>$a//
使用:
參考文獻
http://www.vimer.cn/
http://qixinglu.com/archives/vim_key_mapping
http://easwy.com/blog/archives/advanced-vim-skills-cscope/
http://blog.csdn.net/wooin/archive/2007/10/31/1858917.aspx
http://sinolog.it/?p=1443
下載
除apt-get安裝外的全部已經配置好的vim設置打包以下,直接解壓到home目錄就能夠直接使用了:
下載地址:http://www.kuaipan.cn/file/id_13675463633282823.html
(注意,有systags比較大,大概1.5G,主要是個人include目錄裏有太多的東西,下載後能夠刪除從新參照自動補全創建系統tags來本身生成)