Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1562288
  • 博文数量: 237
  • 博客积分: 5139
  • 博客等级: 大校
  • 技术积分: 2751
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-18 14:48
文章分类

全部博文(237)

文章存档

2016年(1)

2012年(4)

2011年(120)

2010年(36)

2009年(64)

2008年(12)

分类: LINUX

2008-11-28 11:07:24

3. Cscope options                                        *cscope-options*

Use the |:set| command to set all cscope options.   Ideally, you would do
this in one of your startup files (e.g., .vimrc).   Some cscope related
variables are only valid within |.vimrc|.   Setting them after vim has
started will have no effect!

                                                         *cscopeprg* *csprg*
'cscopeprg' specifies the command to execute cscope.   The default is
"cscope".   For example: >
         :set csprg=/usr/local/bin/cscope
<
                                                         *cscopetag* *cst*
If 'cscopetag' set, the commands ":tag" and CTRL-] as well as "vim -t" will
always use |:cstag| instead of the default :tag behavior.   Effectively, by
setting 'cst', you will always search your cscope databases as well as your
tag files.   The default is off.   Examples: >
         :set cst
         :set nocst
<
                                                         *cscopetagorder* *csto*
The value of 'csto' determines the order in which |:cstag| performs a search.
If 'csto' is set to zero, cscope database(s) are searched first, followed
by tag file(s) if cscope did not return any matches.   If 'csto' is set to
one, tag file(s) are searched before cscope database(s).   The default is zero.
Examples: >
         :set csto=0
         :set csto=1
<
                                                 *cscopeverbose* *csverb*
If 'cscopeverbose' is not set (the default), messages will not be printed
indicating success or failure when adding a cscope database.   Ideally, you
should reset this option in your |.vimrc| before adding any cscope databases,
and after adding them, set it.   From then on, when you add more databases
within Vim, you will get a (hopefully) useful message should the database fail
to be added.   Examples: >
         :set csverb
         :set nocsverb
<
                                                       *cscopepathcomp* *cspc*
The value of 'cspc' determines how many components of a file's path to
display.   With the default value of zero the entire path will be displayed.
The value one will display only the filename with no path.   Other values
display that many components.   For example: >
         :set cspc=3
will display the last 3 components of the file's path, including the file
name itself.

==============================================================================
4. How to use cscope in Vim                              *cscope-howtouse*

The first thing you need to do is to build a cscope database for your
source files.   For the most basic case, simply do "cscope -b".   Please
refer to the cscope man page for more details.

Assuming you have a cscope database, you need to "add" the database to Vim.
This establishes a cscope "connection" and makes it available for Vim to use.
You can do this in your .vimrc file, or you can do it manually after starting
vim.   For example, to add the cscope database "cscope.out", you would do:

         :cs add cscope.out

You can double-check the result of this by executing ":cs show".   This will
produce output which looks like this:

# pid     database name                        prepend path
0 28806   cscope.out                          

Once a cscope connection is established, you can make queries to cscope and
the results will be printed to you.   Queries are made using the command
":cs find".   For example:

         :cs find g ALIGN_SIZE

This can get a little cumbersome since one ends up doing a significant
amount of typing.   Fortunately, there are ways around this by mapping
shortcut keys.   See |cscope-suggestions| for suggested usage.

If the results return only one match, you will automatically be taken to it.
If there is more than one match, you will be given a selection screen to pick
the match you want to go to.   After you have jumped to the new location,
simply hit Ctrl-T to get back to the previous one.


==============================================================================
5. Limitations                                           *cscope-limitations*

Cscope support for Vim is only available on systems that support these four
system calls: fork(), pipe(), execl(), waitpid().   This means it is mostly
limited to Unix systems.

Libraries are available for Win95 (win32) which translate a lot of Unix
system calls to the Win32 API.   You can try the GNU-Win32 Project from Cygnus
() or the DJGPP suite of tools
().   I do not know the status of using these with
Vim, so they may or may not work.

Additionally, there are a couple of hard-coded limitations:

     1. The maximum number of cscope connections allowed is 8.   Do you
     really need more?

     2. Doing a |:tjump| when |:cstag| searches the tag files is not
     configurable (e.g., you can't do a tselect instead).

==============================================================================
6. Suggested usage                                       *cscope-suggestions*

Put these entries in your .vimrc (adjust the pathname accordingly to your
setup): >

         if has("cscope")
                 set csprg=/usr/local/bin/cscope
                 set csto=0
                 set cst
                 set nocsverb
                 " add any database in current directory
                 if filereadable("cscope.out")
                     cs add cscope.out
                 " else add database pointed to by environment
                 elseif $CSCOPE_DB != ""
                     cs add $CSCOPE_DB
                 endif
                 set csverb
         endif

By setting 'cscopetag', we have effectively replaced all instances of the :tag
command with :cstag.   This includes :tag, Ctrl-], and "vim -t".   In doing
this, the regular tag command not only searches your ctags generated tag
files, but your cscope databases as well.

Some users may want to keep the regular tag behavior and have a different
shortcut to access :cstag.   For example, one could map Ctrl-_   (underscore)
to :cstag with the following command: >

         map :cstag =expand("")

A couple of very commonly used cscope queries (using ":cs find") is to
find all functions calling a certain function and to find all occurrences
of a particular C symbol.   To do this, you can use these mappings as an
example: >

         map g :cs find 3 =expand("")
         map g :cs find 0 =expand("")

These mappings for Ctrl-] (right bracket) and Ctrl-\ (backslash) allow you to
place your cursor over the function name or C symbol and quickly query cscope
for any matches.
阅读(942) | 评论(0) | 转发(0) |
0

上一篇:cscope的使用

下一篇:xp编程方法

给主人留下些什么吧!~~