VIM/EMACS编辑器及cscope/ctags/etags

发布: 2013-06-07 10:47

这两个编辑器就像瑞士军刀一样灵活而且强大,不过需要你让它的强大表现出来。

在使用它们阅读代码的过程中,经常需要在代码间跳转,跟踪代码的调用关系,更好地理解代码关系。

最近又仔细看了一遍这两个辅助工具cscope/[ce]tags,分析其相似之处与功能差异,

以便在后面的使用过程对它们的选择更合理高效。


cscope与ctags都是独立的linux命令行程序。

cscope针对C/C++语言,ctags/etags则支持多数常用语言。

cscope功能在emacs中叫做xcscope,在包xcscope.el中。

ctags在emacs中叫做etags,在emacs包中自带etags。

VIM与emacs都能使用cscope和tags格式,但是emacs使用的TAGS为etags格式,

使用ctags默认生成的TAGS不能直接用于emacs,

但通过指定ctags参数,可生成兼容etags的TAGS文件。


×)cscope用法:

在emacs中,使用cscope-index-files生成索引

使用cscope-set-init-directory设置代码根目录(索引目录)

在命令行,使用:

find . -name "*.h" -o -name "*.cpp" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" > cscope.files



×)xcscope常用命令列表

http://linux.die.net/man/1/xcscope

* Keybindings:
All keybindings use the "C-c s" prefix, but are usable only while editing a source file, or in the cscope results buffer:

C-c s s Find symbol.
C-c s d Find global definition.
C-c s g Find global definition (alternate binding).
C-c s G Find global definition without prompting.
C-c s c Find functions calling a function.
C-c s C Find called functions (list functions called
from a function).
C-c s t Find text string.
C-c s e Find egrep pattern.
C-c s f Find a file.
C-c s i Find files #including a file.
These pertain to navigation through the search results:

C-c s b Display *cscope* buffer.
C-c s B Auto display *cscope* buffer toggle.
C-c s n Next symbol.
C-c s N Next file.
C-c s p Previous symbol.
C-c s P Previous file.
C-c s u Pop mark.
These pertain to setting and unsetting the variable, 'cscope-initial-directory', (location searched for the cscope database directory):

C-c s a Set initial directory.
C-c s A Unset initial directory.
These pertain to cscope database maintenance:

C-c s L Create list of files to index.
C-c s I Create list and index.
C-c s E Edit list of files to index.
C-c s W Locate this buffer's cscope directory
( "W" --> "where" ).
C-c s S Locate this buffer's cscope directory.
(alternate binding: "S" --> "show" ).
C-c s T Locate this buffer's cscope directory.
(alternate binding: "T" --> "tell" ).
C-c s D Dired this buffer's directory.



×)etags用法

在命令行,使用find . -name "*.php" -print | etags -

在emacs使用visit-tags-table emacs指令切换TAGS文件。

使用ctags 生成etags:find . -name \*php | xargs ctags -e -f TAGS --language-force=php


×)etags常用命令列表

M-. tag
Find first definition of tag (find-tag).
C-u M-.
Find next alternate definition of last tag specified.
C-u - M-.
Go back to previous tag found.
C-M-. pattern
Find a tag whose name matches pattern (find-tag-regexp).
C-u C-M-.
Find the next tag whose name matches the last pattern used.
C-x 4 . tag
Find first definition of tag, but display it in another window (find-tag-other-window).
C-x 5 . tag
Find first definition of tag, and create a new frame to select the buffer (find-tag-other-frame).
M-*

EMACS列编辑: 很简单啊
M-x cua-mode
M-x cua-set-rectangle-mark / C+Retrun



原文: http://qtchina.tk/?q=node/694

Powered by zexport