Linux下編程協助工具輔助vim+ctags+taglist+cppcomplete+cscope+global

來源:互聯網
上載者:User
各個工具的主要功能:

vim:這個是Linux下功能十分強大的編輯器,就不說了。
ctags:產生tag檔案的命令,這個是其它工具的基礎。
taglist:需要ctags的支撐,直接在左邊列出函數列表,全域參數列表。
cppcomplete:需要ctags的支撐,可以補全類型或者函數名。
cscope:比較強大,可以對函數以及部分類型定義進行跳轉,其實cscope是用來替代ctags功能的。
global:貌似和cscope,taglist功能一樣,據說對於大型的工程表現不錯。

各個工具的安裝:
1)vim,ctags,cscope,global,在系統安裝時安裝,或者使用yum安裝。
2)從下面地址下載vim的cscope外掛程式,並放到相應目錄下,如~/.vim/plugin/

http://cscope.sourceforge.net/cscope_vim_tutorial.html
2)taglist,cppcomplete是Vim的外掛程式,從下面地址獲得,然後放到vim相應目錄下即可。

http://www.vim.org/scripts/script.php?script_id=273
http://www.vim.org/scripts/script.php?script_id=527

各個工具的使用:
1)ctags的使用
在終端運行如下命令,將組建檔案tags:
ctags *.cpp
要產生cppcomplete需要的tags檔案的話,需要運行下面的命令:
 ctags -n -f cppcomplete.tags --fields=+ai --C++-types=+p * -L cscope.files
 注意,我在最後使用了參數"-L cscope.files" 這僅僅是借用拉cscope產生的檔案索引來協助ctags去查詢相關工程檔案產生tags。
2)使用taglist
taglist的功能是即時產生當前檔案的函數列表和全域變數列表,便於索引。
在vim中命令模式下使用:
Tlist 開啟或者關閉當前檔案的索引;
TlistSync 立即在開啟的索引視窗中定位當前的游標所在位置屬於哪個函數或者結構定義中。
3)使用cppcomplete
使用很簡單,就是在你需要補全類型成員時,按F8鍵就可以啦。
The default key mapping to complete the code are:

Alt+l in insert mode will try to find the possible completions and display them in a popup menu. Also normal completions to the names in cppcomplete.tags.
Alt+j in insert mode will show the popup menu with the last results. Selecting one of the  items will paste the text.
F8/F9 will work in a similar way as Ctrl+N, Ctrl+P in unextended vim so the script can be used without the popup menu.
F5 in insert mode will lookup the class and display it in a preview window

The key mapping are only tested under Windows and linux and they will not work on all platforms. Changing the mappings is easy.
4)使用cscope
cscope的tag產生最簡單的方法是:
在你的開發工程的最上層目錄執行cscope-indexer,它會遍曆下面的所有目錄,產生兩個檔案,一個是cscope.files,這個檔案記錄需要產生tags的檔案名稱,可以手工修改,另一個是cscope格式的tags檔案cscope.out。
完成後,就可以使用Ctrl-]跳轉尋找類型定義了。
5)使用global
在工程的最上層目錄執行命令:
gtags
等待它完成所有需要的global自己格式的tags的產生。產生完後,可以用如下命令查詢相互關聯類型引用和關聯關係:

代碼:

Gtags xxxx 尋找xxxx的定義
Gtags -r xxxx 尋找xxxx的引用
Gtags -s xxxx 尋找xxxx出現的地方
有時它無法正常分析的類型 可以試試用帶-s 的參數的方式找找類型定義。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.