關於我的vim配置
經常在伺服器上寫代碼,一個朋友提供了關於他的vim配置,在此分享給大家。
介面效果圖:
.vimrc
內容如下
"=========================================================================set nocompatible " be iMproved, requiredfiletype off " required " git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim" set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " let Vundle manage Vundle, requiredPlugin 'gmarik/Vundle.vim' " plugin on GitHub repoPlugin 'shawncplus/phpcomplete.vim'Plugin 'scrooloose/nerdtree'Plugin 'kien/ctrlp.vim'Plugin 'bling/vim-airline'Plugin 'scrooloose/syntastic'Plugin 'vim-scripts/DoxygenToolkit.vim'Plugin 'scrooloose/nerdcommenter' Plugin 'MarcWeber/vim-addon-mw-utils'Plugin 'tomtom/tlib_vim'Plugin 'garbas/vim-snipmate' " Optional:Plugin 'honza/vim-snippets' " plugin from http://vim-scripts.org/vim/scripts.htmlPlugin 'vim-scripts/bufexplorer.zip'Plugin 'vim-scripts/cscope.vim'Plugin 'vim-scripts/taglist.vim' " Plugin 'vim-scripts/winmanager'" Plugin 'vim-scripts/project.tar.gz' call vundle#end() " Brief help" :PluginList - lists configured plugins" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate" :PluginSearch foo - searches for foo; append `!` to refresh local cache" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal filetype plugin on " required syntax on " 自動文法高亮set number " 顯示行號set cursorline " 反白當前行" set ruler " 開啟狀態列尺規set shiftwidth=4 " 設定 << 和 >> 命令移動時的寬度為 4set tabstop=4 expandtab " 設定 tab 長度為 4 個空格set nobackup " 覆蓋檔案時不備份" set autochdir " 自動切換目前的目錄為當前檔案所在的目錄set backupcopy=yes " 設定備份時的行為為覆蓋set ignorecase smartcase " 搜尋時忽略大小寫,但在有一個或以上大寫字母時仍保持對大小寫敏感set nowrapscan " 禁止在搜尋到檔案兩端時重新搜尋" set incsearch " 輸入搜尋內容時就顯示搜尋結果set hlsearch " 搜尋時高亮顯示被找到的文本set noerrorbells " 關閉錯誤資訊響鈴set novisualbell " 關閉使用可視響鈴代替呼叫set t_vb= " 置空錯誤鈴聲的終端代碼set magic " 設定魔術set hidden " 允許在有未儲存的修改時切換緩衝區,此時的修改由 vim 負責儲存set guioptions-=T " 隱藏工具列set guioptions-=m " 隱藏功能表列set smartindent " 開啟新行時使用智能自動縮排set backspace=indent,eol,start " 不設定在插入狀態無法用退格鍵和 Delete 鍵刪除斷行符號符set cmdheight=1 " 設定命令列的行數為 1set laststatus=2 " 顯示狀態列 (預設值為 1, 無法顯示狀態列)set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\ " 設定在狀態行顯示的資訊set errorformat=%m\ in\ %f\ on\ line\ %lset autoindent set softtabstop=4 " 使得按退格鍵時可以一次刪掉 4 個空格 colorscheme molokaiset t_Co=256 "-----------------------------------------------------------------" 擷取當前系統類別型"------------------------------------------------------------------function! MySys() if has("win16") || has("win32") || has("win64") || has("win95") return "windows" elseif has("unix") return "linux" endifendfunction " 使用者目錄變數$VIMFILESif MySys() == "windows" let $VIMFILES = $VIM.'/vimfiles' set backupdir=D://Vim/tmpelseif MySys() == "linux" let $VIMFILES = $HOME.'/.vim' set backupdir=/tmpendif " 設定字型 以及中文支援if has("win32") set guifont=Inconsolata:h12:cANSIendif " 配置多語言環境if has("multi_byte") " UTF-8 編碼 set encoding=utf-8 set termencoding=utf-8 set formatoptions+=mM set fencs=utf-8,gbk if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)' set ambiwidth=double endif if has("win32") source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim language messages zh_CN.utf-8 endifelse echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"endif " 游標到上方視窗,需要<c-w><c-w>k,非常麻煩,現在重新對應為<c-k>nnoremap <C-h> <C-w>hnnoremap <C-j> <C-w>jnnoremap <C-k> <C-w>knnoremap <C-l> <C-w>l "一些不錯的映射轉換文法(如果在一個檔案中混合了不同語言時有用)nnoremap <leader>1 :set filetype=xhtml<CR>nnoremap <leader>2 :set filetype=css<CR>nnoremap <leader>3 :set filetype=javascript<CR>nnoremap <leader>4 :set filetype=php<CR> "-----------------------------------------------------------------" 摺疊配置"" manual 手工定義摺疊" indent 更多的縮排表示更進階別的摺疊" expr 用運算式來定義摺疊" syntax 用文法高亮來定義摺疊" diff 對沒有更改的文本進行摺疊" marker 對文中的標誌摺疊"------------------------------------------------------------------set foldenableset foldmethod=manualset foldlevel=100 " 啟動vim時不要自動摺疊代碼set foldcolumn=0 " 設定摺疊欄寬度 " Python 檔案的一般設定,比如不要 tab 等" autocmd FileType python set tabstop=4 shiftwidth=4 expandtab" autocmd FileType python map <F12> :!python %<CR> " 設定資料字典 ~/.vim/dict/檔案的路徑set complete-=k complete+=k" autocmd filetype javascript set dictionary=$VIMFILES/dict/javascript.dict" autocmd filetype css set dictionary=$VIMFILES/dict/css.dictau FileType php setlocal dict+=$VIMFILES/dict/php.dict "-----------------------------------------------------------------" plugin - winManager 配置 (棄用,很多小bug)"-----------------------------------------------------------------" let g:winManagerWindowLayout="NERDTree,TagList"" let g:winManagerWidth = 35" let g:NERDTree_title="[NERDTree]"" " nmap <silent> <C-m> :if IsWinManagerVisible() <BAR> WMToggle<CR> <BAR> else <BAR> WMToggle<CR>:q<CR> endif <CR>" " nmap <C-m> :WMToggle<CR>" " function! NERDTree_Start()" exec 'NERDTree' " endfunction" " function! NERDTree_IsValid() " return 1" endfunction "-----------------------------------------------------------------" plugin - doxygen toolkit 配置"-----------------------------------------------------------------let g:DoxygenToolkit_briefTag_pre="@brief "let g:DoxygenToolkit_paramTag_pre="@Param " let g:DoxygenToolkit_returnTag="@return " let g:DoxygenToolkit_authorName="jiangyh <jiangyahui@360.cn>"let g:DoxygenToolkit_briefTag_funcName="no"let g:doxygen_enhanced_color=1 map fg : Dox<cr>map ffg : DoxAuthor<cr> "-----------------------------------------------------------------" plugin - NERDTree 配置"-----------------------------------------------------------------let NERDTreeWinPos="left"let NERDTreeWinSize=30" let NERDTreeChDirMode=1 " 改變tree目錄的同時改變工程的目錄 nnoremap <silent><F6> :NERDTreeToggle<CR> "-----------------------------------------------------------------" plugin - ctags程式"-----------------------------------------------------------------if MySys() == "windows" let Tlist_Ctags_Cmd = '"'.$VIMRUNTIME.'/ctags.exe"'elseif MySys() == "linux" let Tlist_Ctags_Cmd = '/usr/bin/ctags'endif set tags=~/acl/tags;nnoremap <silent><F8> :!ctags -R --exclude=*.js --c++-kinds=+p --fields=+iaS --extra=+q .<CR> "-----------------------------------------------------------------" plugin - taglist.vim "-----------------------------------------------------------------let Tlist_Show_One_File = 1 " 不同時顯示多個檔案的tag,只顯示當前檔案的let Tlist_Exit_OnlyWindow = 1 " 如果taglist視窗是最後一個視窗,則退出vimlet Tlist_Use_Right_Window = 1 " 在右側視窗中顯示taglist視窗let Tlist_File_Fold_Auto_Close=1 " 自動摺疊當前非編輯檔案的方法列表let Tlist_Auto_Open = 0let Tlist_Auto_Update = 1let Tlist_Hightlight_Tag_On_BufEnter = 1let Tlist_Enable_Fold_Column = 0let Tlist_Compact_Format = 1" let Tlist_Display_Prototype = 0 nnoremap <silent><F7> :TlistToggle<CR> "-----------------------------------------------------------------" plugin - cscope設定"-----------------------------------------------------------------set cscopequickfix=s-,c-,d-,i-,t-,e- if has("cscope") set csprg=/usr/bin/cscope set csto=1 set cst set nocsverb " add any database in current directory " if filereadable("cscope.out") " cs add cscope.out " endif " set csverb " endif 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>endif "-----------------------------------------------------------------" plugin - project.vim 組織項目列表" \C 遞迴讀取子目錄 \c 讀取當前檔案" \l (列出所有當前層檔案)\L(遞迴),按任何鍵停止" \w (關閉當前層檔案)\W(遞迴)" \g (在項目當前層檔案搜尋)\G(遞迴)" \r 關閉子檔案夾並重新整理當前檔案夾下檔案,\R遞迴開啟檔案夾並重新整理所有檔案" \s 關閉檔案夾並建立,\S遞迴開啟檔案夾並建立" \s 將檔案在水平開啟多個視窗顯示,開啟或關閉資料夾清單" \o 將檔案在一個視窗開啟,開啟或關閉資料夾清單" \v 在右視窗顯示指標停留在project視窗的檔案內容" \i 顯示檔案或檔案夾的設定參數,如filter="*"" \I 顯示檔案或檔案夾的決對路徑和參數" \1 - \9,\f1-\f9,\F1-\F9執行指定命令,\0查詢1-9命令,\f0查詢f1-f9,F1-F9命令" <space>空格擴大project視窗的寬度,恢複寬度"-----------------------------------------------------------------" let proj_window_width=24" let proj_window_increment=12" let loaded_project = 1 " 停用插架" let proj_flags="imstcg" " 自動隱藏project列表" nnoremap <silent><F5> :Project<CR> " F5 開啟project視窗 "-----------------------------------------------------------------" plugin - NERD_commenter.vim 注釋代碼用的," [count],cc 游標以下count行逐行添加註釋(7,cc)" [count],cu 游標以下count行逐行取消注釋(7,cu)" [count],cm 游標以下count行嘗試添加塊注釋(7,cm)" ,cA 在行尾插入 /* */,並且進入插入模式。 這個命令方便寫注釋。" 註:count參數可選,無則預設為選中行或當前行"-----------------------------------------------------------------let NERDSpaceDelims=1 " 讓注釋符與語句之間留一個空格let NERDCompactSexyComs=1 " 多行注釋時樣子更好看 "-----------------------------------------------------------------" plugin - ctrlp 設定"-----------------------------------------------------------------nnoremap <silent> <C-p> :ClearAllCtrlPCache<CR>\|:CtrlP<CR>
使用步驟:
1、下載外掛程式管理器
~/.vim/bundle/Vundle.vim
2、安裝外掛程式
開啟一個檔案
vim ~/.vimrc
進入命令執行安裝
:BundleInstall
3、上傳PHP自動執行個體字典及本色方案,解壓至 .vim 目錄下
以上就是配置VIM的詳細過程,希望對大家的學習有所協助。