關於我的vim配置
經常在服務器上寫代碼,一個朋友提供了關於他的vim配置,在此分享給大家。
界面效果圖:
.vimrc
內容如下
"========================================================================= set nocompatible " be iMproved, required filetype off " required " git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " let Vundle manage Vundle, required Plugin 'gmarik/Vundle.vim' " plugin on GitHub repo Plugin '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.html Plugin '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 " 設定 << 和 >> 命令移動時的寬度為 4 set 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 " 設定命令行的行數為 1 set 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\ %l set autoindent set softtabstop=4 " 使得按退格鍵時可以一次刪掉 4 個空格 colorscheme molokai set t_Co=256 "----------------------------------------------------------------- " 獲取當前系統類型 "------------------------------------------------------------------ function! MySys() if has("win16") || has("win32") || has("win64") || has("win95") return "windows" elseif has("unix") return "linux" endif endfunction " 用戶目錄變量$VIMFILES if MySys() == "windows" let $VIMFILES = $VIM.'/vimfiles' set backupdir=D://Vim/tmp elseif MySys() == "linux" let $VIMFILES = $HOME.'/.vim' set backupdir=/tmp endif " 設置字體 以及中文支持 if has("win32") set guifont=Inconsolata:h12:cANSI endif " 配置多語言環境 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 endif else 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>h nnoremap <C-j> <C-w>j nnoremap <C-k> <C-w>k nnoremap <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 foldenable set foldmethod=manual set 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.dict au 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 <[email protected]>" 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窗口是最後一個窗口,則退出vim let Tlist_Use_Right_Window = 1 " 在右側窗口中顯示taglist窗口 let Tlist_File_Fold_Auto_Close=1 " 自動折疊當前非編輯文件的方法列表 let Tlist_Auto_Open = 0 let Tlist_Auto_Update = 1 let Tlist_Hightlight_Tag_On_BufEnter = 1 let Tlist_Enable_Fold_Column = 0 let 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的詳細過程,希望對大家的學習有所幫助。