本文主要介紹將vim打形成IDE開發環境,如代碼補全,高亮顯示,函數跳轉,函數自動註釋等javascript
首先介紹2款VIM插件管理器:Vbundle,Pathogenphp
本文中的vim插件,均可以經過這2款插件管理軟件進行安裝。具體使用方法,請參考官方說明
下面主要介紹經過手動安裝的方式,安裝VIM插件。css
具體請參考vim配置說明html
使用該插件,須要vim+lua支持,具體配置方法請參考lua安裝java
neocomplete安裝,如下是github地址python
https://github.com/Shougo/neocomplete
步驟1:下載插件git
git clone https://github.com/Shougo/neocomplete
步驟2:安插neocomplete
將下載的源碼複製到vim目錄程序員
cd neocomplete cp -r autoload doc plugin /usr/share/vim/vim74/
步驟3:配置vimrc,使其支持自動補全
neocomplete配置,在/etc/vimrc (/usr/share/vim/vimrc)中加入以下配置github
"Note: This option must set it in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)! " Disable AutoComplPop. let g:acp_enableAtStartup = 0 " Use neocomplete. let g:neocomplete#enable_at_startup = 1 " Use smartcase. let g:neocomplete#enable_smart_case = 1 " Set minimum syntax keyword length. let g:neocomplete#sources#syntax#min_keyword_length = 3 let g:neocomplete#lock_buffer_name_pattern = '\*ku\*' " Define dictionary. let g:neocomplete#sources#dictionary#dictionaries = { \ 'default' : '', \ 'vimshell' : $HOME.'/.vimshell_hist', \ 'scheme' : $HOME.'/.gosh_completions' \ } " Define keyword. if !exists('g:neocomplete#keyword_patterns') let g:neocomplete#keyword_patterns = {} endif let g:neocomplete#keyword_patterns['default'] = '\h\w*' " Plugin key-mappings. inoremap <expr><C-g> neocomplete#undo_completion() inoremap <expr><C-l> neocomplete#complete_common_string() " Recommended key-mappings. " <CR>: close popup and save indent. inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR> function! s:my_cr_function() return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>" " For no inserting <CR> key. "return pumvisible() ? "\<C-y>" : "\<CR>" endfunction " <TAB>: completion. inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>" " <C-h>, <BS>: close popup and delete backword char. inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>" inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>" " Close popup by <Space>. "inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>" " AutoComplPop like behavior. "let g:neocomplete#enable_auto_select = 1 " Shell like behavior(not recommended). "set completeopt+=longest "let g:neocomplete#enable_auto_select = 1 "let g:neocomplete#disable_auto_complete = 1 "inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>" " Enable omni completion. autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS autocmd FileType python setlocal omnifunc=pythoncomplete#Complete autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags " Enable heavy omni completion. if !exists('g:neocomplete#sources#omni#input_patterns') let g:neocomplete#sources#omni#input_patterns = {} endif "let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::' "let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)' "let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::' " For perlomni.vim setting. " https://github.com/c9s/perlomni.vim let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
步驟4:php自動補全配置shell
通過以上配置,默認狀況下已經支持大多數語言的代碼補全
官方已經禁用了php和ruby的代碼補全,由於運行效率太慢
要使用php補全,參考https://github.com/shawncplus/phpcomplete.vim說明
Q: I want to use PHP omni completion. A: Note: You should use this omni completion for PHP. https://github.com/shawncplus/phpcomplete.vim > let g:neocomplete#sources#omni#input_patterns.php = \ '\h\w*\|[^. \t]->\%(\h\w*\)\?\|\h\w*::\%(\h\w*\)\?' <
在這裏,直接在vimrc中加入以下配置,就能夠php自動補全了
let g:neocomplete#sources#omni#input_patterns.php = \ '\h\w*\|[^. \t]->\%(\h\w*\)\?\|\h\w*::\%(\h\w*\)\?'
若是要使用neocomplete推薦的php補全,https://github.com/shawncplus/phpcomplete.vim,請參考以下配置
須要安裝Vbundle,它是一個vim軟件集,且是一個vim插件管理器
https://github.com/VundleVim/Vundle.vim
步驟1 在vim路徑,/usr/share/vim/vim74/ 下創建bundle目錄 cd ~/.vim/bundle git clone git://github.com/shawncplus/phpcomplete.vim.git 步驟2: git clone https://github.com/VundleVim/Vundle.vim.git 在vimrc最開始加入以下配置 set nocompatible " be iMproved, required filetype off " required " set the runtime path to include Vundle and initialize set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " alternatively, pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here') " let Vundle manage Vundle, required Plugin 'VundleVim/Vundle.vim' " The following are examples of different formats supported. " Keep Plugin commands between vundle#begin/end. " plugin on GitHub repo Plugin 'tpope/vim-fugitive' " plugin from http://vim-scripts.org/vim/scripts.html Plugin 'L9' " Git plugin not hosted on GitHub Plugin 'git://git.wincent.com/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'} " All of your Plugins must be added before the following line call vundle#end() " required filetype plugin indent on " required " To ignore plugin indent changes, instead use: "filetype plugin on " " 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 " " see :h vundle for more details or wiki for FAQ " Put your non-Plugin stuff after this line 輸入以下命令運行安裝插件 :PluginInstall 或者 sh執行vim +PluginInstall +qall .vimrc加入以下配置 Plugin 'shawncplus/phpcomplete.vim' Source your .vimrc with :so % or otherwise reload your vim Run the :PluginInstall commmand
http://www.vim.org/scripts/script.php?script_id=987 https://github.com/vim-scripts/DoxygenToolkit.vim 安裝插件 Copy to your '~/.vim/plugin' directory cp -r plugin /usr/shar/vim/vim74/ let g:DoxygenToolkit_commentType = "php" let g:DoxygenToolkit_authorName="coolbaby" 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 let g:DoxygenToolkit_briefTag_pre="@desc function " let g:DoxygenToolkit_paramTag_pre="@params [type] " let g:DoxygenToolkit_returnTag="@return " "let g:DoxygenToolkit_blockHeader="--------------------------------------------------------------------------" "let g:DoxygenToolkit_blockFooter="----------------------------------------------------------------------------" "let g:DoxygenToolkit_authorName="Mathias Lorente" "let g:DoxygenToolkit_licenseTag="My own license"
doxygen使用
註釋操做都在vim命令行模式下操做:
1 註釋類型(C/C++/// 或者, Python:##和#):
在vim中,默認C++註釋爲,可是若是你更喜歡使用///,只須要在你的配置文件.
vimrc中添加以下語句:
let g:DoxygenToolkit_commentType="C++"。
2 許可:
在vim中,將光標放在將要寫doxygen許可註釋的那一行,而後,執行命令:DoxLic
。這將會生成許可註釋並將光標放置在剛纔那一行以後。
3 做者:
在vim中,將光標放在想要添加doxygen做者註釋的地方。而後執行命令:DoxAuthor
。這將會生成一個框架,若是沒有爲其設置變量則將光標放置在@author標籤以後,或者放在在框架以後。
4 函數/類註釋:
在vim中,將光標放置在函數頭部那一行(或者函數的返回變量)或者類。而後執行命令:Dox
。這將生成框架而且將光標放置在@brief標籤後。
5 忽略代碼片斷(只有C/C++):
在vim中,若是你想要忽略全部在塊中的代碼片斷,相似: #ifdef DEBUG ... #endif你只須要執行如下命令:DoxUndoc
(DEBUG)!
6 組:
在vim中,執行命令:DoxBlock
在後面的行中插入一個doxygen塊。
taglist是一個用於顯示定位程序中各類符號的插件,例如宏定義、變量名、結構名、函數名這些東西 咱們將其稱之爲符號(symbols),而在taglist中將其稱之爲tag。
顯然,要想將程序文件中的tag顯示出來,須要事先了解所有tag的信息,並將其保存在一個文件中,而後去解析對應的tag文件。
taglist作的僅僅是將tag文件中的內容解析完後顯示在Vim上而已。
tag掃描以及數 據文件的生成則是由ctags(Exuberant Ctags)這一工具完成的
因此在使用taglist以前,你的電腦須要裝有ctags。
ctags能夠創建源碼樹的標籤索引(標籤就是一個標識符被定義的地方,如函數定義),使程序員在編程時能迅速定位函數、變量、宏定義等位置去查看原形
Ctags工具是用來遍歷源代碼文件生成tags文件,這些tags文件能被編輯器或其它工具用來快速查找定位源代碼中的符號(tag/symbol),如變量名,函數名等。好比,tags文件就是Taglist和OmniCppComplete工做的基礎。
如下是在centos6.7下ctags的下載安裝和配置過程:
參考資料
https://github.com/shawncplus/phpcomplete.vim/wiki/Patched-ctags http://blog.csdn.net/duguteng/article/details/7412652
ctags相關網站
http://ctags.sourceforge.net/ 當前的PHP支持ctags發佈(5.8)不支持當前的PHP版本的新功能名稱空間、特徵或舊功能接口。 有一個改進版的https://ctags.io/ 改進版ctags源碼下載 https://github.com/shawncplus/phpcomplete.vim/raw/master/misc/ctags-5.8_better_php_parser.tar.gz
ctags安裝
wget "https://github.com/shawncplus/phpcomplete.vim/raw/master/misc/ctags-5.8_better_php_parser.tar.gz" -O ctags-5.8_better_php_parser.tar.gz tar xvf ctags-5.8_better_php_parser.tar.gz ./configure make make install 運行 ctags --version 將會看到 Exuberant Ctags Development表示安裝成功
使用ctags
cd /path/to/your/projects/root 運行 ctags -R --fields=+aimS --languages=php 參數說明 -a Access (or export) of class members; Adds the access field like: access: public -i Inheritance information; Adds the inherits field like: inherits:RuntimeException,ExceptionInterface -m Implementation information; Adds the implementation field like: implementation:abstract -S Signature of routine; Adds the signature field like: signature:($a, $b) These extra fields will show up in the tag stack like this: 使用額外的參數字段將會看到相似下面的堆棧調試信息 6 F f handle vendor/monolog/monolog/src/Monolog/Handler/NullHandler.php class:Monolog\Handler::NullHandler access:public signature:(array $record) public function handle(array $record)
Taglist用於列出了當前文件中的全部標籤(宏, 全局變量, 函數名等)
安裝Taglist
方式1:vim-addons install taglist 方式2: 官網http://vim-taglist.sourceforge.net/ https://sourceforge.net/projects/vim-taglist/files/ https://sourceforge.net/projects/vim-taglist/files/vim-taglist/4.6/taglist_46.zip taglist的github地址 https://github.com/vim-scripts/taglist.vim 目前最新版本是4.6 下載以後解壓,拷備目錄中的2個目錄到vim目錄 cp -r doc plugin /usr/share/vim/vim74/
配置Taglist
在Vim配置文件中,可經過"let"語句設定如下變量控制taglist:
Tlist_GainFocus_On_ToggleOpen : 爲1則使用TlistToggle打開標籤列表窗口後會獲焦點至於標籤列表窗口;爲0則taglist打開後焦點仍保持在代碼窗口 Tlist_Auto_Open : 爲1則Vim啓動後自動打開標籤列表窗口 Tlist_Close_On_Select : 選擇標籤或文件後是否自動關閉標籤列表窗口 Tlist_Exit_OnlyWindow : Vim當前僅打開標籤列表窗口時,是否自動退出Vim Tlist_Use_SingleClick : 是否將默認雙擊標答打開定義的方式更改成單擊後打開標籤 Tlist_Auto_Highlight_Tag : 是否高亮顯示當前標籤。命令":TlistHighlightTag"也可達到一樣效果 Tlist_Highlight_Tag_On_BufEnter : 默認狀況下,Vim打開/切換至一個新的緩衝區/文件後,標籤列表窗口會自動將當前代碼窗口對應的標籤高亮顯示。TlistHighlight_Tag_On_BufEnter置爲0可禁止以上行爲 Tlist_Process_File_Always : 爲1則即便標籤列表窗口未打開,taglist仍然會在後臺處理vim所打開文件的標籤 Tlist_Auto_Update : 打開/禁止taglist在打開新文件或修改文件後自動更新標籤。禁止自動更新後,taglist僅在使用:TlistUpdate,:TlistAddFiles,或:TlistAddFilesRecursive命令後更新標籤 Tlist_File_Fold_Auto_Close : 自動關閉標籤列表窗口中非激活文件/緩衝區所在文檔標籤樹,僅顯示當前緩衝區標籤樹 Tlist_Sort_Type : 標籤排序依據,能夠爲"name"(按標籤名排序)或"order"(按標籤在文件中出現的順序,默認值) Tlist_Use_Horiz_Window : 標籤列表窗口使用水平分割樣式 Tlist_Use_Right_Window : 標籤列表窗口顯示在右側(使用垂直分割樣式時) Tlist_WinWidth : 設定水平分割時標籤列表窗口的寬度 Tlist_WinHeight : 設定垂直分割時標籤列表窗口的高度 Tlist_Inc_Winwidth : 顯示標籤列表窗口時容許/禁止擴展Vim窗口寬度 Tlist_Compact_Format : 減小標籤列表窗口中的空白行 Tlist_Enable_Fold_Column : 是否不顯示Vim目錄列 Tlist_Display_Prototype : 是否在標籤列表窗口用標籤原型替代標籤名 Tlist_Display_Tag_Scope : 在標籤名後是否顯示標籤有效範圍 Tlist_Show_Menu : 在圖型界面Vim中,是否如下拉菜單方式顯示當前文件中的標籤 Tlist_Max_Submenu_Item : 子菜單項上限值。如子菜單項超出此上限將會被分隔到多個子菜單中。缺省值爲25 Tlist_Max_Tag_Length : 標籤菜單中標籤長度上限
在vim配置文件/home/user/.vimrc中加入以下的配置:
"-- Taglist setting -- "自動更新taglist let Tlist_Auto_Update = 1 "設置taglist寬度 let Tlist_WinWidth=40 "由於咱們放在環境變量裏,因此能夠直接執行 let Tlist_Ctags_Cmd='ctags' "讓窗口顯示在右邊,0的話就是顯示在左邊 let Tlist_Use_Right_Window=1 "讓taglist能夠同時展現多個文件的函數列表 let Tlist_Show_One_File=0 "非當前文件,函數列表摺疊隱藏 let Tlist_File_Fold_Auto_Close=1 "當taglist是最後一個分割窗口時,自動推出vim let Tlist_Exit_OnlyWindow=1 "爲1則即便標籤列表窗口未打開,taglist仍然會在後臺處理vim所打開文件的標籤 let Tlist_Process_File_Always=1 let Tlist_Inc_Winwidth=0
標籤列表窗口快捷鍵
taglist快捷鍵:
<CR> : 代碼窗口跳轉到標籤列表窗口中光標所在標籤訂義處 o : 在新建代碼窗口中跳轉到標籤列表窗口中光標所在標籤訂義處 P : 跳轉至上一個窗口的標籤處 p : 代碼窗口中內容跳轉至標籤訂義處,光標保持在標籤列表窗口中 t : 在Vim新標籤窗口中跳轉至標籤訂義處。如文件已經在Vim標籤窗口中打開,則跳轉至此標籤窗口 Ctrl-t : 在Vim新標籤窗口處跳轉至標籤訂義處 : 顯示光標當前所在標籤原型。對文件標籤,顯示文件的全路徑名,文件類型和標籤數量。對標籤類型(指如variable/function等類別),顯示標籤類型和擁有標籤的數量;對函數/變量等普通標籤,顯示其定義的原型 u : 更新標籤列表窗口中的標籤信息 s : 切換標籤排序類型(按名稱序或出現順序) d : 移除當前標籤所在文件的全部標籤 x : 擴展/收縮標籤列表窗口 + : 展開摺疊節點* - : 摺疊結點* * : 展開全部結點 = : 摺疊全部節點 [[ : 跳轉至上一個文件標籤的頭部 <Backspace> : 跳轉至上一個文件標籤頭部 ]] : 跳轉至下一個文件標籤頭部 <Tab> : 跳轉至下一個文件標籤頭部 q : 關閉標籤列表窗口 F1 : 顯示幫助**
taglist命令
taglist在Vim中提供瞭如下擴展命令:
:TlistAddFiles {files(s)} [file(s)...] 添加一或多個指定文件(的標籤項)到標籤列表窗口中。文件名錶達式中可以使用通配符(*);如文件名中帶有空格,須要使用反斜槓對空格進行轉義("\ ") :TlistAddFilesRecursive {directory} [{pattern}] 遍歷指定路徑{directory},將與模式{pattern}相匹配的文件加入標籤列表窗口。如未指定pattern,則使用缺省值'*'。如路徑中包含空格,需使用反斜槓'\'轉義("\ ") :TlistClose 關閉標籤列表窗口 :TlistDebug [filename] 記錄taglist插件的調試信息。如指定了filename,則調試信息將被寫入此指定文件(如文件已存在,內容將被覆蓋);如未指定filename,則調試信息寫入腳本的局部變量中 :TlistLock 鎖定標籤列表,而且不處理新打開的文件 :TlistMessage 僅當調試信息寫入腳本局部變量時有效,顯示記錄的調試信息 :TlistOpen 打開並跳轉至標籤列表窗口 :TlistSessionSave {filename} 將當前打開文件及其標籤信息寫入指定文件 :TlistSessionLoad {filename} 從指定文件載入所保存的會話信息 :TlistShowPrototype [filename] [linenumber] 顯示指定文件中指定代碼行或以前的標籤的原型。如未指定文件名/行號,則使用當前文件名/當前行號 :TlistShowTag [filename] [linenumber] 顯示指定文件中指定代碼行或以前標籤名稱。如未指定文件名/行號,則使用當前文件名/當前行號 :TlistHighlightTag 加亮顯示標籤窗口中的當前標籤 :TlistToggle 在打開和關閉狀態間切換標籤窗口的狀態。標籤窗口切換至打開狀態後仍然光標保持在代碼窗口中 :TlistUndebug 中止記錄taglist插件調試信息 :TlistUnlock 解鎖標籤列表,並處理新打開的文件 :TlistUpdate 更新當前緩衝區的標籤信息
taglist全局函數
taglist插件爲Vim提供了一些全局函數,可供其餘插件使用:
Tlist_Update_File_Tags({filename}, {filetype}) 以指定文件類型更新指定文件的標籤信息。如taglist插件此前未處理過指定文件,則會調用ctags對文件進行分析 Tlist_Get_Tag_Prototype_By_Line([{filename}, {linenumber}]) 獲取指定文件中指定行號或以前標籤的原型信息。如未指定文件名/行號,則使用當前緩衝區對應文件/當前行號 Tlist_Get_Tagname_By_Line ([{filename}, {linenumber}]) 獲取指定文件中指定行號或以前標籤的名稱信息。如未指定文件名/行號,則使用當前緩衝區對應文件/當前行號 Tlist_Set_App({appname}) 設置正在控制taglist的插件名稱
使用方法:
http://blog.csdn.net/skyflying2012/article/details/8112144參考
在源碼目錄下,執行ctags -R
對各目錄遞歸建立生成tags文件
用Vim打開源碼文件,以命令模式執行Tlist
,便可啓用Taglist插件,
:TlistToggle
能夠關閉,打開taglist
使用鍵映射關閉打開
nnoremap <silent> <F8> :TlistToggle<CR>
在Vim中加載代碼文件後,可使用如下命令控制taglist
:TlistOpen 打開並將輸入焦點至於標籤列表窗口 :TlistClose 關閉標籤列表窗口 :TlistToggle 切換標籤列表窗口狀態(打開←→關閉),標籤列表窗口是否得到焦點取決於其餘配置 ctl-w + w 或ctl-w + 方向鍵 窗口切換(taglist本質上是一個vim分隔窗口,所以可使用ctl-w系列快捷鍵對窗口進行切換操做) 使用鼠標單擊切換當前窗口,或在標籤列表窗口某標籤上雙擊使代碼窗口內窗跳轉至標籤訂義 標籤列表窗口內,當光標停留在某個標籤之上時,回車鍵可切換代碼窗口內容至標籤訂義; 'o',在分隔窗口中顯示;'t',在vim新標籤窗口中顯示
官方使用手冊
http://vim-taglist.sourceforge.net/manual.html
進入vim後用命令":Tlist"打開/關閉taglist窗口
幫助文檔
:help taglist.txt
摺疊用於把緩衝區內某一範圍內的文本行顯示爲屏幕上的一行。就像一張紙,要它縮短
些,能夠把它摺疊起來:
+------------------------+ | 行 1 | | 行 2 | | 行 3 | |_______________________ | \ \ \________________________\ / 被摺疊的行 / /________________________/ | 行 12 | | 行 13 | | 行 14 | +------------------------+
那些文本仍然在緩衝區內而沒有改變。受到摺疊影響的只是文本行顯示的方式。
摺疊的好處是,經過把多行的一節摺疊成帶有摺疊提示的一行,會使你更好地瞭解對文本
的宏觀結構。
摺疊方式foldmethod
vim提供如下6種方法來選定摺疊方式:
manual 手工定義摺疊 indent 更多的縮進表示更高級別的摺疊 expr 用表達式來定義摺疊 syntax 用語法高亮來定義摺疊 diff 對沒有更改的文本進行摺疊 marker 對文中的標誌摺疊
摺疊級別foldlevel
'foldlevel' 是個數值選項:數字越大則打開的摺疊更多。
當 'foldlevel' 爲 0 時,全部的摺疊關閉。
當 'foldlevel' 爲正數時,一些摺疊關閉。
當 'foldlevel' 很大時,全部的摺疊打開。
摺疊欄foldcolumn
'foldcolumn' 是個數字,它設定了在窗口的邊上表示摺疊的欄的寬度。當爲0時,沒有摺疊欄。最大是12。
一個打開的摺疊由一欄來表示,頂端是 '-',其下方是 '|'。這欄在摺疊結束的地方結束。當摺疊嵌套時,嵌套的摺疊出如今被包含的摺疊右方一個字符位置。
一個關閉的摺疊由 '+' 表示。
當摺疊欄太窄而不能顯示全部摺疊時,顯示一數字來表示嵌套的級別。
在摺疊欄點擊鼠標,能夠打開和關閉摺疊:
點擊 '+' 打開在這行的關閉摺疊
在任何其餘非空字符上點擊,關閉這行上的打開摺疊
在vim配置文件/home/user/.vimrc中加入以下的配置:
"--fold setting vim摺疊設置-- " 用縮進來定義摺疊 set foldmethod=indext " 啓動vim時不要自動摺疊代碼 set foldlevel=100 " 設置摺疊欄寬度 set foldcolumn=5
經常使用命令
za 打開/關閉在光標下的摺疊 zA 循環地打開/關閉光標下的摺疊 zo 打開 (open) 在光標下的摺疊 zO 循環打開 (Open) 光標下的摺疊 zc 關閉 (close) 在光標下的摺疊 zC 循環關閉 (Close) 在光標下的全部摺疊 zM 關閉全部摺疊 zR 打開全部的摺疊 幫助文檔 :help usr_28.txt :help fold.txt
參考資料
http://www.cnblogs.com/zhangsf/archive/2013/06/13/3134409.html
github地址
https://github.com/scrooloose/syntastic
環境需求
須要vim支持autocmd, eval, file_in_path, modify_fname, quickfix, reltime, and user_commands
檢查以上vim依賴是否安裝,出現+表示知足要求
vim --version |grep autocmd
這個插件是用來作靜態語法檢查的,支持多語言,好比 Ruby,Python 和 JavaScript 等。實際上這個插件是個接口,背後的語法檢查是交給各個語言本身的檢查器,Ruby 實際使用ruby -c命令,JavaScript 使用 jshint,jslint 等。
注意安裝後jshint須要在系統環境變量中,不然須要指定path:
g:syntastic_jshint_exec
指定jshint的配置文件目錄:
g:syntastic_javascript_jshint_conf
最後但並不是最不重要的:syntastic不知道如何本身作任何語法檢查。爲了獲得有意義的結果,你須要安裝相應的文件外部檢查你使用的類型
安裝syntastic with Pathogen
1.須要先安裝Pathogen
https://github.com/tpope/vim-pathogen git clone https://github.com/tpope/vim-pathogen cd vim-pathogen cp -r autoload /usr/share/vim/vim74/
在vimrc中加入配置
execute pathogen#infect()
2.安裝syntastic
mkdir -p /usr/share/vim/vim74/bundle cd /usr/share/vim/vim74/bundle git clone https://github.com/scrooloose/syntastic.git
3.推薦配置syntastic
set statusline+=%#warningmsg# set statusline+=%{SyntasticStatuslineFlag()} set statusline+=%* let g:syntastic_always_populate_loc_list = 1 let g:syntastic_auto_loc_list = 1 let g:syntastic_check_on_open = 1 let g:syntastic_check_on_wq = 0 let g:syntastic_error_symbol = 'err!' let g:syntastic_warning_symbol = '!' nmap <A-up> :lprev<cr> nmap <A-down> :lnext<cr> nmap <A-right> :ll<cr>
4.安裝php語法分析器phpcs
方式1 pear install PHP_CodeSniffer 方式2 composer global require "squizlabs/php_codesniffer=*"
vim幫助文檔:help syntastic
安裝方式
用插件管理器pathogen.vim或者Vundle安裝
cd ~/.vim/bundle git clone https://github.com/scrooloose/nerdtree.git
啓動vim,自動打開NERDtree
autocmd vimenter * NERDTree
How can I open a NERDTree automatically when vim starts up if no files were specified?
autocmd StdinReadPre * let s:std_in=1 autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
映射快捷鍵
map <C-n> :NERDTreeToggle<CR>
若是隻剩下NERDTree最後一個窗口,如何關閉NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
Can I have different highlighting for different file extensions?
不一樣的擴展名,顯示不一樣的顏色
" NERDTress File highlighting function! NERDTreeHighlightFile(extension, fg, bg, guifg, guibg) exec 'autocmd filetype nerdtree highlight ' . a:extension .' ctermbg='. a:bg .' ctermfg='. a:fg .' guibg='. a:guibg .' guifg='. a:guifg exec 'autocmd filetype nerdtree syn match ' . a:extension .' #^\s\+.*'. a:extension .'$#' endfunction call NERDTreeHighlightFile('jade', 'green', 'none', 'green', '#151515') call NERDTreeHighlightFile('ini', 'yellow', 'none', 'yellow', '#151515') call NERDTreeHighlightFile('md', 'blue', 'none', '#3366FF', '#151515') call NERDTreeHighlightFile('yml', 'yellow', 'none', 'yellow', '#151515') call NERDTreeHighlightFile('config', 'yellow', 'none', 'yellow', '#151515') call NERDTreeHighlightFile('conf', 'yellow', 'none', 'yellow', '#151515') call NERDTreeHighlightFile('json', 'yellow', 'none', 'yellow', '#151515') call NERDTreeHighlightFile('html', 'yellow', 'none', 'yellow', '#151515') call NERDTreeHighlightFile('styl', 'cyan', 'none', 'cyan', '#151515') call NERDTreeHighlightFile('css', 'cyan', 'none', 'cyan', '#151515') call NERDTreeHighlightFile('coffee', 'Red', 'none', 'red', '#151515') call NERDTreeHighlightFile('js', 'Red', 'none', '#ffa500', '#151515') call NERDTreeHighlightFile('php', 'Magenta', 'none', '#ff00ff', '#151515')
How can I change default arrows?
改變默認的箭頭
let g:NERDTreeDirArrowExpandable = '▸' let g:NERDTreeDirArrowCollapsible = '▾'
http://vim.wikia.com/wiki/Understanding_VIMRUNTIME