Automatically load cscope. Out in VIM (Vim supports cscope) [zz]

Source: Internet
Author: User

In the initial growth of vimer, the combination of VIM + ctags + cs.pdf is basically a must for every vimer. Although ctags are powerful enough, csags can do more. Next, let's share a part of my vimrc script about cssag. This script can automatically search for cssag. Out in any subdirectory of the project and add it in.


First, we will share a small script to help us generate csmetadata. Out and ctags in the project.

I named this file CS. Sh.

[Java] View plaincopy
    1. #! /Bin/sh
    2. Find.-Name"*. H"-o-name "*. c"-o-name "*. cpp"-o-name "*. Java "\
    3. > Cscope. Files
    4. Cscope-bkq-I cscope. Files
    5. Ctags-R

Using the find. method above may cause CS to fail to find the file. You can find $ pwd xxxx.


Note that in the above script, the generated cssag. Files stores relative paths rather than absolute paths. In this case, you cannot open the corresponding file containing the search result when searching for tags in cssag. How can this problem be avoided? There are two methods:

1. In CS. in the sh script, the find command is followed by the variable pro_path. This pro_path is the directory of the current project and cs.pdf at this time. files stores the absolute paths of all project files.

2. When Cs is added, a prepend path is added.

[Java] View plaincopy
    1. : CS add [cscope. Out] [pre-path]

I used the second method, so I had the following vimrc snippet,

[Java] View plaincopy
  1. If has ("CSAs ")
  2. Set csprg =/usr/bin/cs.pdf
  3. Set CSTO =0
  4. Set CST
  5. Set csverb
  6. Set cspc =3
  7. "Add any database in current dir
  8. If filereadable ("cscope. Out ")
  9. CS add cscope. Out
  10. "Else search cswhere. out elsewhere
  11. Else
  12. Let cscope_file = findfile ("Cscope. Out ",".;")
  13. Let cscope_pre = matchstr (cscope_file,".*/")
  14. If! Empty (cscope_file) & filereadable (cscope_file)
  15. EXE"CS Add" cscope_file cscope_pre
  16. Endif
  17. Endif
  18. Endif
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.