Using Vim+ctags+cscope

Source: Internet
Author: User
Tags function prototype requires sort tagname advantage
1. Why the Ctags+cscope is used in conjunction with:
Why cooperate, because, for example, cscope can provide more functions such as search function. But Ctags is far more files than cscope support. For example, to access a Java project file, the Cscope is less capable, such as class recognition, but we can still use some of its functions, such as finding what function called the function.
In addition, a little note that ctags can not take advantage of the Quickfix window, and Cscope is available, which is also the benefit of cscope. Generally, if there is only a C + + file, use Cscope more, if it is other files, then use Ctags more.
Whether with ctags or cscope, can use Winmanager and taglist, to achieve the left above is the file list, the following is TagList, the right is the File browser window effect. But TagList rely on ctags, if use cscope,ctags still need to use. For the specific method of Winmanager and taglist, see Vim configuration file.

2. Build the database and let vim use:
The general practice is to generate these files in the top-level directory. Vim then opens at the top and uses the Winmanager mentioned below to navigate to the inside directory.
(1) ctags Generate tags file:
Ctags-r. You can search all the files in the directory and generate tags files.
In order to generate the most tags:
C + +: Ctags--extra=+q--fields=+saim--c++-kinds=+lpx--c-kinds=+lpx-r.
Java this: Ctags--java-kinds=+l-r.

(mainly--xx-kinds control to analyze what things, such as--java-kinds=+l to add (+) local variable, the default is what, no, with ctags--list-kinds can know, Off is not analyzed by default, otherwise it is analyzed)
Cscope can only parse C/C++/LEX/YACC files.

Then in vim: Set Tags=path/to/tags (with, delimited, can be multiple)

(2) cscope generate cscope.in.out cscope.out cscope.po.out file:
Since cscope default does not look at files other than. c. yacc. Lex, let's say you're looking for C and C + + other files, like this:
Find. -name "*.h"-o-name "*.c"-o-name "*.cc" > Cscope.files
Cscope-bkq-i Cscope.files
(Find Java files in the same vein)
And, for pure C files, you can:
Cscope-rbkq./Can.

Then in VIM: CS add path/to/cscope.out
If you want to regenerate, use:!CSCOPE-RBKQ, then use: CS Reset re-read into.

3. Ctags Management Jump Stack:
Ctags is designed to find everything you want, such as at the definition of a class, at the definition of a function. Support for a variety of languages, but the original design is defined for the function, so, ctags to find functions definition is particularly effective, like a function prototype is not the default tag.
(1) Vim support tags of the command: (these commands at compile time to add ctags support to use)
Vim relies on the built-in commands to support the use of ctags to get tags files.
: Tags list the current you jump to the stack, you can know the current location (unfortunately not with the Quickfix window)
: Tag jumps to: Top of tags list (bottom of stack)
: Tag tagname jumps to the definition of tagname
CTRL +] Press stack (jump to mark definition) Ctrl+w] opens in a new window that is sideways (: Stag tagname)
n ctrl+t out of the stack (after jumping n times, will make your: tags list of tables shortened)-cross the file, with Ctrl + O to jump back.

: Tselect tagname can list all the same tagname, you can jump to the corresponding entry by number.
: Tnext jumps to the next same tagname place
: tprevious
: TFirst
: Tlast

Match//To surround, let vim know that there is a regular type
such as: Tselect/^write_ can match the start of write

: Set ignorecase can ignore the case at any time, for example when: Tag tagname. If you set this and want the case to be valid, add \c after the expression
But if you want it to work, add \c after the expression
The above expressions are all wrapped up in//.


4. Cscope look at the Vim configuration file and the previous document.

5. Use path:
Sometimes, we want to define additional paths to access certain files. and convenient GF (goto file, in normal mode, press GF, will open the file under the cursor, it will search the path down), find (not support regular search, usage: Find Netrw.vim) and other commands.

The path option defines a list of directories that, when used with Gf,find and ctrl-w f commands, will look for the corresponding file in the directory list defined by the path option if you are using a relative path. The path option separates the directory names with commas. We still take the source code of Vim 7.0 as an example (the source code is placed in the ~/src/vim70/directory).

For this project, our path option is set as follows:
Set path=.,/usr/include,,~/src/vim70/**

To explain the meaning of each item a little bit, see the help page for the path option for more details:
. Search in the directory where the current file is located
/usr/include Search in the/usr/include directory
, and search in the current work path
~/src/vim70/** Search in all sub-directory Trees of ~/SRC/VIM70!!

6. Multi-file browsing using Minibufexplorer:
Because the use of Winmanager and taglist, so tabe look bad, with buffer will be more convenient.
However, vim comes with the buffer management tool only: LS,: bnext,: bdelete and other commands, here with Minibufexplorer. The advantage is that each buffer is listed on top of the visualization. Still used: bnext and other commands.
Then, in vim set up, with Shift+tab to switch buffer, very convenient.
To close a buffer without exiting the window, press D on the label, which is the Minibufexplorer command. A

7. Taglist
Reminder s to toggle sort by name (uppercase, then lowercase, every first letter inside) or in order of occurrence
Update the list with U (you can call Ctags again by default)
In addition, you set the click in VIMRC to open the corresponding location

8. Winmanager
s to toggle Sort by XX, R to reverse sort
In addition, switch between the various Windows, CTRL + ARROW keys faster ~ ~ ~

9. Vimgrep look up text or grep plugin to find text:
Ctags found the--list-kinds in the instructions, you can use: Tag tagname find out these tags,cscope also find what it can find, you can use: CS find g/d/c/t/e tagname find the corresponding things, where t means to find the text, especially e means to find it with egrep. The single is found in the Cscope database.
However, many times, you still need to search the file itself, or think of a specific subdirectory search, and support the regular type.
(1) can be used: Vimgrep command:
: Vimgrep is a vim built-in grep, and if you use: grep, it is the grep that lets vim invoke the external system. Use: The advantage of Vimgrep is that it is not dependent on the system, so it can be used on every system. But it will slow down, because it will put each file into buffer, and then analyze.
Simple to use:
: Vimgrep/pattern/path
Where pattern is regular, such as \<main\> denotes the main word
Path is a shell meta-character, such as./ssf/**/*.java that searches all subdirectories under the SSF directory, and all Java files nested in subdirectories.
(2) You can also use the grep plug-in, the following commands are supported by the regular type:
: Grep finds in the specified file
: Rgrep Recursive Lookup
: Bgrep found in open buffer
He will ask you more information, such as which files to find, in which directory to find, very convenient.
Such as:
Search for pattern: can fill \<get_real_path\> (match word, not string)
Search in Files: can be filled *.java

10. Highlight text:
: ColorScheme can select a topic.
In. Vim, create your own colors Doc plugin syntax four directories, doc and plugin users put plugin files and doc files, syntax used to place the instructional syntax highlighting the file, and colors is used to place the highlighted theme. I am currently using the desert theme.

11. Plugins currently in use:
A.vim
Color_sample_pack.vim
Minibufexpl.vim
Taglist.vim
Winmanager.vim (Winfileexplorer.vim Wintagexplorer.vim)
Code_complete.vim #这个好好看看它的代码体吧, very simple, but very efficient tab completion of a lot of things, such as calling a function, after (press TAB, you can fill out the various parameters of the type.) For example, it is convenient to generate main,for,while,#define automatically.
Grep.vim
Nerd_commenter.vim


12. Color Related:
First, enter in Vim: Runtime Syntax/colortest.vim can print out the colors you can use today. There are only so few. Include Bold. So, this is the end of the use of Vim no gvim color, or no gvim color normal reason. But, if you make a good adjustment, you can still meet your requirements.
In addition, various color themes are not allowed, such as functions, to be highlighted individually, as this requires syntax help. This requires you to find the grammar file alone, which is what is the function and should highlight why color. Put the grammar file in the ~/.vim/syntax.
I was from the official website Cpp.vim put in the ~/.vim/syntax directory, so the. cpp file can have more highlighting.
However, C.vim is I find from other places, the official online search C.vim not work, I do not change. Currently used C.vim as follows, mainly highlighted the function name and C keyword. And Cpp.vim is used C.vim, so the default also let Cpp.vim support the same effect.

To read and change this simple file, you need the following knowledge:
: The Hi command always takes a graphical interface (GUI) as an example to set the foreground and background color. Because of the limitation of the command terminal's color display, VIM can use a much less color than the GUI on the command line, so the color of the graphics interface and the command line interface is set separately when the Hi command is used. For the black and white terminal is indifferent color, and color terminal with Cterm to express, the foreground is "CTERMFG", and the background is "CTERMBG". Here is a table:

Terminal type foreground background color annotation
Term--black and white terminal
Cterm CTERMFG CTERMGB Color terminal
GUI GUIFG GUIBG Graphics interface
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.