Find symbol only in given files using cscope in vim

82

Is it possible to restrict the scope of search to given files with cscope?

No. Cscope itself doesn't let you do that so Vim's cscope integration doesn't either.

If you want to get out of this specific hole, you may have to ponder a few things…

  1. Is The tool you are using the right tool if it doesn't do what you want?

  2. Why, exactly, do you want to jump to that specific main() in that specific file? What do you do next?

    The way I see it, jumping to a main() doesn't seem to serve any purpose in and of itself as it is usually an entry point. As such, "jump to main() in foo.c" is not much better than "jump to foo.c". It seems to be just another intermediary step.

  3. Is there another way to do exactly that?

  4. Should I abandon that workflow in favour of a better one?

If you know there is a main() in foo.c, there are a few simpler alternatives to cscope, like:

:grep main foo.c

or:

:find +/main foo.c
Share:
82

Related videos on Youtube

srgsanky
Author by

srgsanky

Updated on January 03, 2023

Comments

  • srgsanky
    srgsanky over 1 year

    I want to go to a symbol (say main) in a given file. Is it possible to restrict the scope of search to given files with cscope?

    :cs find s main

    Without this, when I look for a symbol like main, I get hundred plus results in my project and I have to identify and type the number like 90 to navigate to the symbol.

    The option of going to the file of interest and searching for the symbol using vim search is cumbersome for common words like "main" which may be present a handful of times in the file.

  • gerula
    gerula over 8 years
    Asus Transformer TF 101 is an Android tablet. When I migrated from Windows to Ubuntu on my Dell laptop I followed the steps mentioned in your answer. Now I intend to transform my Asus tablet ( it has keyboard dock) which now runs under Adroid, in a notebook running Debian or Ubuntu. And that is what I don't know to do it. Thank you.