This document explains how to use Vim's cscope interface.
Cscope is a tool like ctags, but think of it as ctags on steroids since it
does a lot more than what ctags provides. In Vim, jumping to a result from
a cscope query is just like jumping to any tag; it is saved on the tag stack
so that with the right keyboard mappings, you can jump back and forth between
functions as you normally would with |tags|.
1. Cscope introduction |cscope-intro|
2. Cscope related commands |cscope-commands|
3. Cscope options |cscope-options|
4. How to use cscope in Vim |cscope-howtouse|
5. Limitations |cscope-limitations|
6. Suggested usage |cscope-suggestions|
7. Availability & Information |cscope-info|
This is currently for Unix only.
{Vi does not have any of these commands}
==============================================================================
1. Cscope introduction *cscope-intro*
The following text is taken from a version of the cscope man page:
-----
Cscope is an interactive screen-oriented tool that helps you:
Learn how a C program works without endless flipping through a thick
listing.
Locate the section of code to change to fix a bug without having to
learn the entire program.
Examine the effect of a proposed change such as adding a value to an
enum variable.
Verify that a change has been made in all source files such as adding
an argument to an existing function.
Rename a global variable in all source files.
Change a constant to a preprocessor symbol in selected lines of files.
It is designed to answer questions like:
Where is this symbol used?
Where is it defined?
Where did this variable get its value?
What is this global symbol's definition?
Where is this function in the source files?
What functions call this function?
What functions are called by this function?
Where does the message "out of space" come from?
Where is this source file in the directory structure?
What files include this header file?
Cscope answers these questions from a symbol database that it builds the
first time it is used on the source files. On a subsequent call, cscope
rebuilds the database only if a source file has changed or the list of
source files is different. When the database is rebuilt the data for the
unchanged files is copied from the old database, which makes rebuilding
much faster than the initial build.
-----
When cscope is normally invoked, you will get a full-screen selection
screen allowing you to make a query for one of the above questions.
However, once a match is found to your query and you have entered your
text editor to edit the source file containing match, you cannot simply
jump from tag to tag as you normally would with vi's Ctrl-] or :tag
command.
Vim's cscope interface is done by invoking cscope with its line-oriented
interface, and then parsing the output returned from a query. The end
result is that cscope query results become just like regular tags, so
you can jump to them just like you do with normal tags (Ctrl-] or :tag)
and then go back by popping off the tagstack with Ctrl-T. (Please note
however, that you don't actually jump to a cscope tag simply by doing
Ctrl-] or :tag without remapping these commands or setting an option.
See the remaining sections on how the cscope interface works and for
suggested use.)
==============================================================================
2. Cscope related commands *cscope-commands*
*:cscope* *:cs* *:scs* *:scscope* *E259* *E262*
All cscope commands are accessed through suboptions to the main cscope
command ":cscope". The shortest abbreviation is ":cs". The ":scscope"
command does the same and also splits the window (short: "scs").
The available subcommands are:
add : Add a new cscope database/connection.
USAGE :cs add {file|dir} [pre-path] [flags]
[pre-path] is the pathname used with the -P command to cscope.
[flags] are any additional flags you want to pass to cscope.
EXAMPLES >
:cscope add /usr/local/cdb/cscope.out
:cscope add /projects/vim/cscope.out /usr/local/vim
:cscope add cscope.out /usr/local/vim -C
<
find : Query cscope. All cscope query options are available
except option #5 ("Change this grep pattern").
USAGE :cs find {querytype} {name}
{querytype} corresponds to the actual cscope line
interface numbers as well as default nvi commands:
0 or s: Find this C symbol
1 or g: Find this definition
2 or d: Find functions called by this function
3 or c: Find functions calling this function
4 or t: Find assignments to
6 or e: Find this egrep pattern
7 or f: Find this file
8 or i: Find files #including this file
EXAMPLES >
:cscope find c vim_free
:cscope find 3 vim_free
<
These two examples perform the same query. >
:cscope find 0 DEFAULT_TERM
<
Executing this example on the source code for Vim 5.1 produces the
following output:
Cscope tag: DEFAULT_TERM
# line filename / context / line
1 1009 vim-5.1-gtk/src/term.c <>
#define DEFAULT_TERM (char_u *)"amiga"
2 1013 vim-5.1-gtk/src/term.c <>
#define DEFAULT_TERM (char_u *)"win32"
3 1017 vim-5.1-gtk/src/term.c <>
#define DEFAULT_TERM (char_u *)"pcterm"
4 1021 vim-5.1-gtk/src/term.c <>
#define DEFAULT_TERM (char_u *)"ansi"
5 1025 vim-5.1-gtk/src/term.c <>
#define DEFAULT_TERM (char_u *)"vt52"
6 1029 vim-5.1-gtk/src/term.c <>
#define DEFAULT_TERM (char_u *)"os2ansi"
7 1033 vim-5.1-gtk/src/term.c <>
#define DEFAULT_TERM (char_u *)"ansi"
8 1037 vim-5.1-gtk/src/term.c <>
# undef DEFAULT_TERM
9 1038 vim-5.1-gtk/src/term.c <>
#define DEFAULT_TERM (char_u *)"beos-ansi"
10 1042 vim-5.1-gtk/src/term.c <>
#define DEFAULT_TERM (char_u *)"mac-ansi"
11 1335 vim-5.1-gtk/src/term.c <>
term = DEFAULT_TERM;
12 1459 vim-5.1-gtk/src/term.c <>
if (STRCMP(term, DEFAULT_TERM))
13 1826 vim-5.1-gtk/src/term.c <>
term = DEFAULT_TERM;
14 1833 vim-5.1-gtk/src/term.c <>
term = DEFAULT_TERM;
15 3635 vim-5.1-gtk/src/term.c <>
p = find_builtin_term(DEFAULT_TERM);
Enter nr of choice ( to abort):
The output shows several pieces of information:
1. The tag number (there are 15 in this example).
2. The line number where the tag occurs.
3. The filename where the tag occurs.
4. The context of the tag (e.g., global, or the function name).
5. The line from the file itself.
help : Show a brief synopsis.
USAGE :cs help
*E260* *E261*
kill : Kill a cscope connection (or kill all cscope connections).
USAGE :cs kill {num|partial_name}
To kill a cscope connection, the connection number or a partial
name must be specified. The partial name is simply any part of
the pathname of the cscope database. Kill a cscope connection
using the partial name with caution!
If the specified connection number is -1, then _ALL_ cscope
connections will be killed.
reset : Reinit all cscope connections.
USAGE :cs reset
show : Show cscope connections.
USAGE :cs show
*:cstag* *E257*
If you use cscope as well as ctags, |:cstag| allows you to search one or
the other before making a jump. For example, you can choose to first
search your cscope database(s) for a match, and if one is not found, then
your tags file(s) will be searched. The order in which this happens
is determined by the value of |csto|. See |cscope-options| for more
details.
|:cstag| performs the equivalent of ":cs find g" on the identifier when
searching through the cscope database(s).
|:cstag| performs the equivalent of |:tjump| on the identifier when searching
through your tags file(s).
阅读(2079) | 评论(0) | 转发(0) |