2010年3月16日 星期二

Vim + Trinity + Source Explorer + Tag List + NERD_tree + ctags

在Linux打造一個類似Source Insight的IDE環境.在Linux裏一直希望能有個好用的找程式碼環境,
試過用wine + source insight, 搜尋速度還是太慢, 會導致找code跟不上思慮的問題.
也用過從windows + source insight + samba, 結果更慢.

今天突然看到一個勉強類似source insight的環境了.
使用Vim + Trinity + Source Explorer + Tag List + NERD_tree + ctags,這樣子用起來還ok,比完全沒有好不少.

系統必要套件:
apt-get install  exuberant-ctags  cscope


Trinity + Source Explorer + Tag List + NERD_tree <== 四個都是vim的plugin
Trinity它是一個管理Source Explorer + Tag List + NERD_tree的plugin,畫面如下圖:

請將下面的設定,寫入$HOME/.vimrc裏, 按F8時,則三個視窗皆會開啟,再按一次時,則全關閉.
" Open and close all the three plugins on the same time
nmap <C-F7> :TrinityToggleAll<CR>
" Open and close the srcexpl.vim separately
nmap <C-F9> :TrinityToggleSourceExplorer<CR>
" Open and close the taglist.vim separately
nmap <C-F10> :TrinityToggleTagList<CR>
" Open and close the NERD_tree.vim separately
nmap <C-F11> :TrinityToggleNERDTree<CR>


Source Explorer
這是一個自動顯示定義的功能, Trinity會將它呈現在最底部的視窗.

NERD_tree
算是檔案列表功能, Trinity會將它呈現在右邊的視窗.
當focus在這個tree windows時,請在你想開啟的檔案或目錄名稱上按"o",即可.

Tag List
標籤資訊,比如它會列出這個檔案裏的所有Tag, Trinity會將它呈現在左邊的視窗.
當你在程式碼裏,想進入tag的程式時,請按"ctrl+]",返迴時,請按"ctrl+t"
在使用tag list前,請記得要先用
ctags -R
建立程式碼的索引檔喔!如果沒有ctags命令的話,用apt-get install安裝看看吧! tag list這邊老實講,跟我想像中的有差距,我不能從這個list裏去選我想要看的tag耶^^||
ctags這是最常用到的,可能會有兩種版本,舊的 ctags 只能用於 C 程式碼。exuberant ctags 則可用於 C/C++、Java、Fortran……等等。
svn問題:
使用svn checkout出來的程式碼,會有一份相同的在目錄.svn下,這時如果用-R參數制作tags文件,
會包含多份一樣的標記,可以用--exclude將它排除掉:
ctags -R --exclude=.svn


我還有在$HOME/.vimrc裏多設定一個,讓vim啟動滑鼠的功能.這樣才能用滑鼠改變視窗大小.
set mouse=nv


cscope
當你希望能有尋找關鍵字功能的話,可以慮加掛個cscope_maps.vim.
在使用cscope前必需先建資料庫,預設cscope建立的資料庫只有*.c及*.h,如果想要其它的副檔名,
則必需先產生cscope.files,如下:
find -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.h' > cscope.files

產生cscope.files後,再執行cscope -Rbkq去產生cscope.out, cscope.in.out, cscope.po.out這三個檔案.
其中cscope.out是基本的symbols index,後兩個檔案是-q產生的快速尋找檔.

當你同時有cscope+ctags後,可以使用下面的方法找keyword
:cstag /keyword


cscope的部份使用命令資料如下
This generates the file cscope.out. It is to be executed from the source code root directory à la
ctags. You then open the file as before, relative to the source code root directory, and make a
cscope connection with the command :cs add cscope.out. You can verify existing cscope
connections by typing :cs show.
What you can search for from inside of Vim can be seen using :cs. For instance, to go to a
particular file, or a header of a source file, simply type :cs f f stdio.h for opening stdio.h or :cs f f
foo.c.
For searching for functions called by a function foo.c, type :cs f d foo.c. This lists out the functions
called by foo.c. For functions calling foo.c, type :cs f c foo.c.
To search for an egrep pattern, type :cs f e varName and so on. For a list of the available options,
type :cs. It displays a range of available options.
Now, if you have both ctags and cscope, you can type :cstag /foo to search for a function or enum
or whatever that contains foo.

資料來源:
take it easy:vim+trinity+tabbar
vim with mouse
Vim编译器配合ctags实现函数原型快速定位
Vim-Gnome + Ctags + Taglist + Winmanager
Source Explorer
NERD_tree demo
vim常用插件
在linux下用vim取代source insight (vim 6.4)
Vim tags 的使用
vim學習
不是打 vi 的廣告, vim 的 search 搜尋功能
Trace Code的好幫手: GVim+Ctags+Cscope
听峰's Blog > vim+ctags+taglist+cscope+cppcomplete+global
Lunux Journal:Vim for C Programmers

打造自己的VIM: 源碼追蹤(ctags+cscope)及預覽視窗SrcExpl

沒有留言:

一個小故事讓我們明白資金流通的意義

“又是炎熱小鎮慵懶的一天。太陽高掛,街道無人,每個人都債台高築,靠信用度日。這時,從外地來了一位有錢的旅客,他進了一家旅館,拿出一張1000 元鈔票放在櫃檯,說想先看看房間,挑一間合適的過夜,就在此人上樓的時候---- 店主抓了這張1000 元鈔,跑到隔壁屠戶那裡支付了他欠的肉錢...