How to let cscope use absolute path in cscope.out file?

后端 未结 6 762
野的像风
野的像风 2021-02-02 02:11

Everytime after load a cscope.out in Vim, I need to change Vim\'s \"pwd\" to the same directory as cscope.out file is under, which might be due to that cscope use relative path

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 02:56

    The cscope tutorial has a very simple workaround for this problem:

    11.Try setting the $CSCOPE_DB environment variable to point to a Cscope database you create, so you won't always need to launch Vim in the same directory as the database. This is particularly useful for projects where code is split into multiple subdirectories. Note: for this to work, you should build the database with absolute pathnames: cd to /, and do

    find /my/project/dir -name '*.c' -o -name '*.h' > /foo/cscope.files
    

    Then run Cscope in the same directory as the cscope.files file (or use 'cscope -i /foo/cscope.files'), then set and export the $CSCOPE_DB variable, pointing it to the cscope.out file that results):

    cd /foo
    cscope -b
    CSCOPE_DB=/foo/cscope.out; export CSCOPE_DB   
    

    (The last command above is for Bourne/Korn/Bash shells: I've forgotten how to export variables in csh-based shells, since I avoid them like the plague).

    You should now be able to run 'vim -t foo' in any directory on your machine and have Vim jump right to the definition of 'foo'. I tend to write little shell scripts (that just define and export CSCOPE_DB) for all my different projects, which lets me switch between them with a simple 'source projectA' command.

提交回复
热议问题