⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 if_cscope.txt

📁 MSYS在windows下模拟了一个类unix的终端
💻 TXT
字号:
*if_cscope.txt* For Vim version 5.8.  Last change: 2000 May 06		  VIM REFERENCE MANUAL    by Andy Kahn							*cscope* *Cscope*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 itdoes a lot more than what ctags provides.  In Vim, jumping to a result froma cscope query is just like jumping to any tag; it is saved on the tag stackso that with the right keyboard mappings, you can jump back and forth betweenfunctions 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 selectionscreen 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 yourtext editor to edit the source file containing match, you cannot simplyjump from tag to tag as you normally would with vi's Ctrl-] or :tagcommand.Vim's cscope interface is done by invoking cscope with its line-orientedinterface, and then parsing the output returned from a query.  The endresult is that cscope query results become just like regular tags, soyou 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 notehowever, that you don't actually jump to a cscope tag simply by doingCtrl-] or :tag without remapping these commands or setting an option.See the remaining sections on how the cscope interface works and forsuggested use.)==============================================================================2. Cscope related commands				*cscope-commands*							*:cscope* *:cs*All cscope commands are accessed through suboptions to the main cscopecommand, |:cscope|.  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	    1. :cs add /usr/local/cdb/cscope.out	    2. :cs add /projects/vim/cscope.out /usr/local/vim	    3. :cs 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	    1. :cs find c vim_free	    2. :cs find 3 vim_free	    Examples #1 and #2 perform the same query.	    3. :cs find 0 DEFAULT_TERM	    Executing example #3 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 <<GLOBAL>>			 #define DEFAULT_TERM (char_u *)"amiga"	       2   1013  vim-5.1-gtk/src/term.c <<GLOBAL>>			 #define DEFAULT_TERM (char_u *)"win32"	       3   1017  vim-5.1-gtk/src/term.c <<GLOBAL>>			 #define DEFAULT_TERM (char_u *)"pcterm"	       4   1021  vim-5.1-gtk/src/term.c <<GLOBAL>>			 #define DEFAULT_TERM (char_u *)"ansi"	       5   1025  vim-5.1-gtk/src/term.c <<GLOBAL>>			 #define DEFAULT_TERM (char_u *)"vt52"	       6   1029  vim-5.1-gtk/src/term.c <<GLOBAL>>			 #define DEFAULT_TERM (char_u *)"os2ansi"	       7   1033  vim-5.1-gtk/src/term.c <<GLOBAL>>			 #define DEFAULT_TERM (char_u *)"ansi"	       8   1037  vim-5.1-gtk/src/term.c <<GLOBAL>>			 # undef DEFAULT_TERM	       9   1038  vim-5.1-gtk/src/term.c <<GLOBAL>>			 #define DEFAULT_TERM (char_u *)"beos-ansi"	      10   1042  vim-5.1-gtk/src/term.c <<GLOBAL>>			 #define DEFAULT_TERM (char_u *)"mac-ansi"	      11   1335  vim-5.1-gtk/src/term.c <<set_termname>>			 term = DEFAULT_TERM;	      12   1459  vim-5.1-gtk/src/term.c <<set_termname>>			 if (STRCMP(term, DEFAULT_TERM))	      13   1826  vim-5.1-gtk/src/term.c <<termcapinit>>			 term = DEFAULT_TERM;	      14   1833  vim-5.1-gtk/src/term.c <<termcapinit>>			 term = DEFAULT_TERM;	      15   3635  vim-5.1-gtk/src/term.c <<update_tcap>>			 p = find_builtin_term(DEFAULT_TERM);	    Enter nr of choice (<CR> 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    kill  : Kill a cscope connection.	    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!    reset : Reinit all cscope connections.	    USAGE   :cs reset    show  : Show cscope connections.	    USAGE   :cs show							*:cstag*If you use cscope as well as ctags, |:cstag| allows you to search one orthe other before making a jump.  For example, you can choose to firstsearch your cscope database(s) for a match, and if one is not found, thenyour tags file(s) will be searched.  The order in which this happensis determined by the value of |csto|.  See |cscope-options| for moredetails.|:cstag| performs the equivalent of ":cs find g" on the identifier whensearching through the cscope database(s).|:cstag| performs the equivalent of |:tjump| on the identifier when searchingthrough your tags file(s).==============================================================================3. Cscope options					*cscope-options*Use the |:set| command to set all cscope options.  Ideally, you would dothis in one of your startup files (e.g., .vimrc).  Some cscope relatedvariables are only valid within |.vimrc|.  Setting them after vim hasstarted 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" willalways use |:cstag| instead of the default :tag behavior.  Effectively, bysetting 'cst', you will always search your cscope databases as well as yourtag 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, followedby tag file(s) if cscope did not return any matches.  If 'csto' is set toone, tag file(s) are searched before cscope database(s).  The default is zero.Examples:>	:set csto=0>	:set csto=1							*cscopeverbose* *csverb*If 'cscopeverbose' not set (the default), messages will not be printedindicating success or failure when adding a cscope database.  Ideally, youshould reset this option in your |.vimrc| before adding any cscope databases,and after adding them, set it.  From then on, when you add more databaseswithin Vim, you will get a (hopefully) useful message should the database failto be added.  Examples:>	:set csverb>	:set nocsverb==============================================================================4. How to use cscope in Vim				*cscope-howtouse*The first thing you need to do is to build a cscope database for yoursource files.  For the most basic case, simply do "cscope -b".  Pleaserefer 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 startingvim.  For example, to add the cscope database "cscope.out", you would do:	:cs add cscope.outYou can double-check the result of this by executing ":cs show".  This willproduce output which looks like this: # pid	  database name			      prepend path 0 28806  cscope.out			      <none>Once a cscope connection is established, you can make queries to cscope andthe results will be printed to you.  Queries are made using the command":cs find".  For example:	:cs find g ALIGN_SIZEThis can get a little cumbersome since one ends up doing a significantamount of typing.  Fortunately, there are ways around this by mappingshortcut 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 pickthe 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 foursystem calls: fork(), pipe(), execl(), waitpid().  This means it is mostlylimited to Unix systems.Libraries are available for Win95 (win32) which translate a lot of Unixsystem calls to the Win32 API.  You can try the GNU-Win32 Project from Cygnus(http://www.cygnus.com/misc/gnu-win32) or the DJGPP suite of tools(http://www.delorie.com/djgpp/).  I do not know the status of using these withVim, 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 yoursetup):	if has("cscope")		set csprg=/usr/local/bin/cscope		set csto=0		set cst		set nocsverb		cs add cscope.out		set csverb	endifBy setting 'cscopetag', we have effectively replaced all instances of the :tagcommand with :cstag.  This includes :tag, Ctrl-], and "vim -t".  In doingthis, the regular tag command not only searches your ctags generated tagfiles, but your cscope databases as well.Some users may want to keep the regular tag behavior and have a differentshortcut to access :cstag.  For example, one could map Ctrl-_  (underscore)to :cstag with the following command:	map <C-_> :cstag <C-R>=expand("<cword>")<CR><CR>A couple of very commonly used cscope queries (using ":cs find") is tofind all functions calling a certain function and to find all occurrencesof a particular C symbol.  To do this, you can use these mappings as anexample:	map g<C-]> :cs find 3 <C-R>=expand("<cword>")<CR><CR>	map g<C-\> :cs find 0 <C-R>=expand("<cword>")<CR><CR>These mappings for Ctrl-] (right bracket) and Ctrl-\ (backslash) allow you toplace your cursor over the function name or C symbol and quickly query cscopefor any matches.==============================================================================7. Cscope availability and information			*cscope-info*If you do not already have cscope (it did not come with your compilerlicense or OS distribution), then you can download it for free from:	http://cscope.sourceforge.net/This is released by SCO under the BSD license.If you want a newer version of cscope, you will probably have to buy it.According to the nvi documentation:	You can buy version 13.3 source with an unrestricted license	for $400 from AT&T Software Solutions by calling +1-800-462-8146.In Solaris 2.x, if you have the C compiler license, you will also havecscope.  Both are usually located under /opt/SUNWspro/binSGI developers can also get it.  Currently a tardist file can be found at:	ftp://ftp.openage.com/pub/Sgi/Binaries/Cscope-13_3_tardist.gz	https://toolbox.sgi.com/toolbox/utilities/cscope/The second one is for those who have a password for the SGI toolbox.There is source to an older version of a cscope clone (called "cs") availableon the net.  Due to various reasons, this is not supported with Vim.The cscope interface/support for Vim was originally written byAndy Kahn <ackahn@netapp.com>.  The original structure (as well as a tinybit of code) was adapted from the cscope interface in nvi.  Please reportany problems, suggestions, patches, et al., you have for the usage ofcscope within Vim to him. vim:tw=78:ts=8:sw=8:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -