gVIM+ctags+Taglist+winmanager搭建IDE


對於一個初級程序員,Vim和Emacs始終是一個很難跨越的欄,在11年的時候,接觸Linux,從而也自然的學習Vim,但是那時候真就是不習慣,Windows的習慣始終無法改過來,隨着畢業就不了了之。。。

今年,有從事了單片機開發的工作,至少碰上code了,於是乎想在Vim上動動腦經,學習一下,也參考網上的資料,終於搞了一天,弄出來了,於是就記錄一下,是個好習慣,不是嗎?

首先,所有的安裝包都可以從vim官網下載,安裝gvim,我的安裝路徑是d盤的program files(后來想想還是直接放在d盤好~~),這個時候的vim自帶的功能已經很強大了,但是做一個大項目還是有限吃力,所以才會有IDE的出現,方便我們的開發。我這里也是很粗略的,其實還有很大的空間可以提升!~

Ctags是什么?官網的解釋是:

Ctags generates an index (or tag) file of language objects found in source files that allows these items to be quickly and easily located by a text editor or other utility. A tag signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object).

Taglist呢??

The "Tag List" plugin is a source code browser for the Vim editor. It provides an overview of the structure of source code files and allows you to efficiently browse through source code files in different programming languages. It is the top-rated and most-downloaded plugin for the Vim editor.

The taglist plugin groups and displays the functions, classes, structures, enumerations, macro definitions and other parts of a source code file in a Vim window. The taglist plugin will automatically highlight the current tag. You can jump to the definition of a tag by selecting the tag name from the taglist window. For a list of features supported by the taglist plugin, visit the features page.

他倆的結合就能碰觸火花~~哈哈!我之前一直在cfree下編輯代碼,然后在別的編譯器里編譯,給個cfree的截圖:

 

 

左邊的就是函數(宏定義等)列表,點擊一個就會使光標制指定到程序相應的位置去,方便我們查找函數的位置,上面兩個就是實現這個功能的。

Taglist文件的壓縮包里都有doc和plugin兩個文件,對應vim安裝目錄下的doc和plugin,看出點什么了吧,分別把兩個文件里的文件copy到vim安裝目錄下,這樣就安裝好了,簡單吧~;對於ctags,我起初解壓在d盤的program files文件里,結果怎么地都不成功,后來我考慮到program files有個空格,於是我干脆把ctags解壓在d盤下,並添加在系統變量里,這才是我的函數列表出來了,狂喜!對於winmanager插件,安裝很簡單,和taglist一樣。接下去的事情就是在編譯_vimrc文件。

第二,我把自己的_vimrc的內容顯示如下:

  1 set nocompatible
  2 source $VIMRUNTIME/vimrc_example.vim
  3 source $VIMRUNTIME/mswin.vim
  4 behave mswin
  5 syntax enable
  6 syntax on 
  7 set guifont=Courier\ New:h13
  8 set nu!
  9 set ts=4
 10 set sw=4
 11 set smartindent
 12 set laststatus=2
 13 set cursorline
 14 set autoindent
 15 set cindent
 16 set linebreak
 17 set hidden
 18 set gdefault
 19 set scrolloff=5
 20 set ruler        " 在編輯過程中,在右下角顯示光標位置的狀態行
 21 set hlsearch    " 高亮顯示搜索結果
 22 set incsearch    " 查詢時非常方便,如要查找book單詞,當輸入到/b時,會自動找到
 23 set ignorecase smartcase
 24 set foldmethod=syntax
 25 set foldlevel=100       " Don't autofold anything (but I can still fold manually)
 26 filetype pluginindenton       " 加了這句才可以用智能補全
 27 set showmatch       " 設置匹配模式,類似當輸入一個左括號時會匹配相應的那個右括號
 28 set noexpandtab
 29 set tabstop=4
 30 set nobk
 31 
 32 
 33 "--------------------------------------------------------------------------------
 34 " 代碼折疊
 35 "--------------------------------------------------------------------------------
 36 set foldmarker={,}
 37 "set foldmethod=marker
 38 set foldmethod=syntax
 39 set foldlevel=100       " Don't autofold anything (but I can still fold manually)
 40 "set foldopen-=search   " don't open folds when you search into them
 41 "set foldopen-=undo     " don't open folds when you undo stuff
 42 "set foldcolumn=4
 43 
 44 
 45 "Taglist------------------------------------------------
 46 "==================================================
 47 let Tlist_Show_Menu=1
 48 let Tlist_Ctags_Cmd='D:\ctags58\ctags.exe'”這句話可有可無,但我還是加了,以防萬一
 49 let Tlist_Auto_Open=1
 50 let Tlist_File_Fold_Auto_Close=0
 51 let Tlist_Compact_Format=1
 52 let Tlist_Enable_Fold_Column=1
 53 let Tlist_Sort_Type="order"
 54 set tags=tags;
 55 set autochdir         " 自動設置目錄為正在編輯的文件所在的目錄
 56 
 57 filetype plugin on
 58 
 59 " taglist configuration vimrc file.
 60 "
 61 " Maintainer:     Bruce Ouyang <bruce.oy@gmail.com>
 62 "
 63 let Tlist_Display_Prototype = 1
 64 let Tlist_Sort_Type = "order"           "使taglist以tag名字進行排序
 65 let Tlist_Show_One_File = 1            "不同時顯示多個文件的tag,只顯示當前文件的
 66 let Tlist_Exit_OnlyWindow = 1          "如果taglist窗口是最后一個窗口,則退出vim
 67 let Tlist_Use_Right_Window = 0         "在右側窗口中顯示taglist窗口
 68 let Tlist_Use_SingleClick = 1          "單擊tag就跳轉到定義
 69 let Tlist_GainFocus_On_ToggleOpen = 1  "使用:TlistToggle打開taglist窗口時,輸入焦點在taglist窗口中
 70 nmap <silent> <F9> :TlistToggle<CR>    "打開tag窗口,這個是設置快捷鍵
 71 
 72 """"""""""""""
 73 ""winmanager
 74 """"""""""""""
 75 let g:winManagerWindowLayout='FileExplorer|BufExplorer|TagList'
 76 "nmap <silent> <F10> :WMToggle<cr>
 77 nmap wm :WMToggle<cr> " 是nomal模式的命令,不是Ex模式的,這個是設置快捷鍵
 78 
 79 
 80 """"""""""""""""""""""""""""""""""""""""""""""
 81 ""omni completion 
 82 """"""""""""""""""""""""""""""""""""""""""""""
 83 set nocp
 84 set ofu=syntaxcomplete#Complete
 85 
 86 set diffexpr=MyDiff()
 87 function MyDiff()
 88   let opt = '-a --binary '
 89   if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
 90   if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
 91   let arg1 = v:fname_in
 92   if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
 93   let arg2 = v:fname_new
 94   if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
 95   let arg3 = v:fname_out
 96   if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
 97   let eq = ''
 98   if $VIMRUNTIME =~ ' '
 99     if &sh =~ '\<cmd'
100       let cmd = '""' . $VIMRUNTIME . '\diff"'
101       let eq = '"'
102     else
103       let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
104     endif
105   else
106     let cmd = $VIMRUNTIME . '\diff'
107   endif
108   silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
109 endfunction

效果圖:

 按下wm,如下:

哈哈!I get it!~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM