Cscope with Vim

Kiran Jv
2 min readAug 14, 2021

--

Using Cscope is quite handy but getting in and out of the vim for every search in cscope GUI is quite inconvenient. I have got something to share that help you to overcome this.

Building the database for Cscope
Execute the below command in the source directory (ex: myapplication/src)
$ cscope -b -q -R

Run the following command to use the cscope GUI for finding and parsing the files & definitions and redirects you to a cscope GUI as shown below
$ cscope -d

General Cscope GUI

Using Cscope with Vim
Assuming you are in the folder where you have created the cscope database (check if you can see cscope.out file in the src directory)

Run vim command without a file name and this opens a new file, get the cscope menu by running the following command
$ vim
$ cs
(in new file from vim, esc + :cs)

Use the add command of cscope to attach the database
:cs add cscope.out
To check if the database id successfully added use the following command
:cs show

Now you can use your old way of cscope from vim, here are some examples
:cs find g <some_function_name>
:cs find f <file_name>

Challenges while using Cscope with Vim

  1. I felt it is not convenient to landing a new file/definition which you searched for and missing the source file. We can avoid this by tuning the above command used,
    :tab cs find g <some_function_name>
    :tab cs find f <file_name>
    This makes your search open in a new tab and you can use :tabn and :tabp to switch between the next and previous tabs respectively.
  2. Have you thought of one big problem we will be facing here … case-sensitivity !!
    To do this, you must set the csprg variable in vimrc. Add the following line in vimrc file and save the file.
    set csprg=cscope\ -C

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Kiran Jv
Kiran Jv

Written by Kiran Jv

A software Engineer passionate about technology and wealth creation who likes to engage in reading.

No responses yet

Write a response