History Report a problem
Article Edit this page Discussion

Automatically create and update cscope database

From Vim Tips Wiki

Jump to: navigation, search
 

Tip 1509Previous TipNext Tip

Created: June 21, 2007 Complexity: basic Author: Zhaojun WU Version: 7.0


In order to create or update the cscope database in current directory, the following key mapping would help a bit:

nmap <F11> :!find . -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' > cscope.files ;
  \ cs kill -1<CR>:cs add cscope.out<CR>

In the above mapping, I use "find" to collect the C/C++ source code files and (re)create the cscope database; then "kill -1" to kill all cscope database connections and finally, the newly created "cscope.out" database is added by "cs add cscope.out".

There are two limitations in this key mapping:

  1. the current directory should be the root path of the project
  2. I don't know how to get the current cscope data connection number, so that I use "kill -1" to kill "all" cscope database connections, since actually I always only create one connections in one Vim instance. It is not practical if you are using multiple data connections in one Vim instance.

[edit] Alternate version

Related to limitation #2 above, it's not actually necessary to kill the cscope connection. The command cs reset can accomplish this purpose, if cscope.out is already selected as the cscope file. This gives the following variant:

nmap <F11> :!find . -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' > cscope.files<CR>\
  :!cscope -b -i cscope.files -f cscope.out<CR>\
  :cs reset<CR>

Note that this assumes that there already exists a connection to the cscope.out file (which is the case if you tell Vim to automatically init the cscope connection at startup).

[edit] Comments

 

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Automatically create and update cscope database"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation