database vim 无法连接到 cscope 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6450265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:14:33  来源:igfitidea点击:

vim cannot connect to cscope database

databasevimtagsctagscscope

提问by Aijaz Baig

I have opensuse 11.4 installed. Vim is version 7. Now I normally use it to browse the linux kernel source. So I generated the cscope database inside a directory within my home folder i.e. /home/aijazbaig1/cscope_DB/ and I got 3 files viz. cscope.out, cscope.po.out and cscope.in.out besides the cscope.files file which contains a list of all the relevant files which I want to search.

我已经安装了 opensuse 11.4。Vim 是第 7 版。现在我通常用它来浏览 linux 内核源代码。所以我在我的主文件夹中的一个目录中生成了 cscope 数据库,即 /home/aijazbaig1/cscope_DB/ 并且我得到了 3 个文件,即。cscope.out、cscope.po.out 和 cscope.in.out 除了包含我想要搜索的所有相关文件的列表的 cscope.files 文件。

Additionally I have added the following to my .bashrc:

此外,我已将以下内容添加到我的 .bashrc 中:

CSCOPE_DB=/home/aijazbaig1/cscope_DB/cscope.out
export CSCOPE_DB

But when I do a :cscope showfrom within vim it says there are no connections. Can anyone please let me know what is going wrong.

但是当我:cscope show从 vim 中执行 a 时,它说没有连接。任何人都可以让我知道出了什么问题。

Keen to hear from you,

渴望听到你的消息,

回答by Wesley Bland

This is mentioned in the comments above, but I want to make sure it's preserved in an answer.

上面的评论中提到了这一点,但我想确保它保留在答案中。

The issue that came up for me was that vim didn't know where to look for the cscope database. When I added

我遇到的问题是 vim 不知道在哪里查找 cscope 数据库。当我添加

cs add $CSCOPE_DB

to my .vimrc. Everything came out fine.

到我的.vimrc. 一切都很好。

回答by blackstrype

I figure since I've made the visit, I would try responding.

我想既然我已经访问过,我会尝试做出回应。

I was getting this error when searching using ctrl-space s (or any search for that matter):

使用 ctrl-space 进行搜索(或针对该问题的任何搜索)时,我收到此错误:

E567: no cscope connections

E567: 没有 cscope 连接

I finally found the full solution at http://cscope.sourceforge.net/cscope_vim_tutorial.html, Step 11.

我终于在http://cscope.sourceforge.net/cscope_vim_tutorial.html 的第 11 步找到了完整的解决方案。

The idea is that you create a list of source files to be included in the view of cscope, generate the cscope.out in the same location, and update the export path accordingly:

这个想法是创建一个要包含在 cscope 视图中的源文件列表,在同一位置生成 cscope.out,并相应地更新导出路径:

  • find /my/project/dir -name '*.c' -o -name '*.h' > /foo/cscope.files
  • cscope -R -b(this may take a while depending on the size of your source)
  • export CSCOPE_DB=/foo/cscope.out(put this in your .bashrc/.zshrc/other-starting-script if you don't want to repeat this every time you log into the terminal)
  • find /my/project/dir -name '*.c' -o -name '*.h' > /foo/cscope.files
  • cscope -R -b(这可能需要一段时间,具体取决于源的大小)
  • export CSCOPE_DB=/foo/cscope.out(如果您不想每次登录终端时都重复此操作,请将其放在您的 .bashrc/.zshrc/other-starting-script 中)

回答by Guru

You need to add a "cscope connection", like this in vim:

您需要添加一个“cscope 连接”,就像在 vim 中这样:

:cscope add $PATH_TO_CSCOPE.out 

See :help csfor more examples.

有关:help cs更多示例,请参见。

回答by ArsalanHAwan

Here's how I explore linux kernel source using cscope:

下面是我如何使用 cscope 探索 linux 内核源代码:

I use vim as my editor.

我使用 vim 作为我的编辑器。

  1. While standing inside the kernel source root directory, run cscopein interactive mode while recursively going through subdirectories during search for source files:
  1. 站在内核源代码根目录中,cscope以交互模式运行,同时在搜索源文件期间递归遍历子目录:

cscope -R

cscope -R

When run for the first time, it will generate the database file with the name: cscope.outinside the current directory. Any subsequent runs will use the already generated database.

第一次运行时,它会cscope.out在当前目录中生成名称为:的数据库文件。任何后续运行都将使用已生成的数据库。

  1. Search for anything or any file and open it.
  2. Set cscope tags in vim to make the :tagand CTRL-]commands search through cscope first and then ctags' tags:
  1. 搜索任何内容或任何文件并打开它。
  2. 在 vim 中设置 cscope 标签,使:tagCTRL-]命令先搜索 cscope,然后搜索 ctags 的标签:

:set cscopetag

:set cscopetag

  1. Set cscope database inside current VIM session:
  1. 在当前 VIM 会话中设置 cscope 数据库:

:cs add cscope.out

:cs add cscope.out

Now you can use CTRL-]and CTRL-tas you would do in ctags to navigate around! :)

现在您可以像在 ctags 中一样使用CTRL-]andCTRL-t来导航!:)

回答by Rasmus B?k

I ran into a similar problem with no cscope connections on ubuntu 18.04, then I discovered my .vimrc file does not load the CSCOPE_DB variable. Looked a little around and found a solution.

我在 ubuntu 18.04 上遇到了没有 cscope 连接的类似问题,然后我发现我的 .vimrc 文件没有加载 CSCOPE_DB 变量。环顾四周,找到了解决办法

You can just copy this directly in to your .vimrc file.

您可以直接将其复制到您的 .vimrc 文件中。

Part of the code loads your cscope file from your directory. The keybinds are just a nice bonus. Hope this helps.

部分代码从您的目录加载您的 cscope 文件。键绑定只是一个不错的奖励。希望这可以帮助。

回答by HuyLe

I have the same issue on my PC. For now, to solve the issue:

我的电脑上也有同样的问题。现在,要解决这个问题:

  1. On terminal execute: which is cscope

  2. Open .vimrc file to edit: set csprg=/usr/bin/cscope

  1. 在终端执行: which is cscope

  2. 打开 .vimrc 文件进行编辑: set csprg=/usr/bin/cscope