On large projects, there might be many definitions over many different files and folders for a given symbol. Usually the one you want is the one that is unique to the local area you are working in.

e.g. if there is a magic_answer() in /proj/foo/bar/utils.c and a magic_answer() in /proj/xyz/abc/utils.c and you are editing a file in /proj/xyz/def/ you probably want the definition under /proj/xyz/...

I used to use ctags, and created tags files in nested folders depending on which folders I worked on frequently. I set up the tags= variable in .vimrc to try to find a tags file as deep in the directory structure that I was in as possible, and then working its way up to the top of the project if necessary, and this worked really well.

I'm trying to use cscope now, and it's not working as well. I use the standard cscope_maps.vim with minor changes. So in my large project, I'm getting many many hits for some definitions. I have to look through them all and visually select the one in the folder nearest to me, which is slow. In some cases it's really even more obvious than my example above - I obviously want the one near me in the tree compared to having to go up 6 directory levels and descend again.

Is there any way to tell cscope or Vim to give me the one that is closer to me in the directory tree?

  • This could be possible via scripting but neither cscope nor vim have any knowledge of your code and thus can't provide such a feature out of the box. – romainl Nov 25 '16 at 10:09
  • 1
    Also, did you consider :help include-search? – romainl Nov 25 '16 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.