Vim Tips Wiki
Jaspax (talk | contribs)
No edit summary
(→‎Comments: remove unhelpful link)
(11 intermediate revisions by 8 users not shown)
Line 1: Line 1:
  +
{{TipNew
{{TipProposed
 
|id=0
+
|id=1509
|previous=0
+
|previous=1508
|next=0
+
|next=1510
|created=June 21, 2007
+
|created=2007
 
|complexity=basic
 
|complexity=basic
 
|author=[[User:Wuzhaojun|Zhaojun WU]]
 
|author=[[User:Wuzhaojun|Zhaojun WU]]
 
|version=7.0
 
|version=7.0
  +
|subpage=/200712
  +
|category1=C
  +
|category2=Integration
 
}}
 
}}
 
In order to create or update the cscope database in current directory, the following key mapping would help a bit:
 
In order to create or update the cscope database in current directory, the following key mapping would help a bit:
Line 12: Line 15:
 
<pre>
 
<pre>
 
nmap <F11> :!find . -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' > cscope.files ;
 
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>
+
\:!cscope -b -i cscope.files -f cscope.out<CR>
  +
\:cs kill -1<CR>:cs add cscope.out<CR>
 
</pre>
 
</pre>
   
Line 19: Line 23:
 
There are two ''limitations'' in this key mapping:
 
There are two ''limitations'' in this key mapping:
 
# the current directory should be the root path of the project
 
# the current directory should be the root path of the project
# 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.
+
# 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.
   
 
==Alternate version==
 
==Alternate version==
 
Related to limitation #2 above, it's not actually necessary to kill the cscope connection. The command <code>cs reset</code> can accomplish this purpose, if cscope.out is already selected as the cscope file. This gives the following variant:
 
Related to limitation #2 above, it's not actually necessary to kill the cscope connection. There is a command "cs reset" that can accomplish this purpose, if cscope.out is already selected as the cscope file. This gives the following variant:
 
   
 
<pre>
 
<pre>
nmap <F11> :!find . -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' > cscope.files<CR>\
+
nmap <F11> :!find . -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' > cscope.files<CR>
:!cscope -b -f cscope.files -i cscope.out<CR>\
+
\:!cscope -b -i cscope.files -f cscope.out<CR>
:cs reset<CR>
+
\:cs reset<CR>
 
</pre>
 
</pre>
   
Line 34: Line 37:
   
 
==Comments==
 
==Comments==
  +
How do you do it in Windows. How to tell windows cmd shell to change directory to the project folder and build cscope DB there?
 
  +
:The directory change is easy, just use the "cd" command just like on Unix (but with backslash separators). The harder part is getting a list of files. You might be able to use <code>dir /b /s *.c</code> and the same for *.h, or you could use Vim to create the list of files using {{help|prefix=no|glob()}} or {{help|prefix=no|globpath()}}. Other than that, cscope itself works in pretty much the same way no matter what system you're on. --[[User:Fritzophrenic|Fritzophrenic]] ([[User talk:Fritzophrenic|talk]]) 15:46, July 2, 2013 (UTC)
----
 
  +
::But, how to pass the current working directory information to "cd", and then how to run cscope from that directory ?
[[Category:C]] <!-- Unless there is a cscope catagory that could be contained in Catagory:C -->
 
  +
:::Just like for any other external command. Actually from within Vim, you can just use Vim's built-in {{help|prefix=no|:cd}} command to get to the directory you want. Or use {{help|prefix=no|:lcd}}. Then use <code>:!path\to\cscope.exe</code> to run cscope from that directory. If you must, you can use the cmd.exe cd command instead, like <code>:!cd some\path & path\to\cscope.exe</code>. If you need Vim's current directory, you can use {{help|prefix=no|getcwd()}}. --[[User:Fritzophrenic|Fritzophrenic]] ([[User talk:Fritzophrenic|talk]]) 19:54, July 3, 2013 (UTC)
[[Category:Integration]] <!-- May be cscope if there are many cscope related tips -->
 

Revision as of 19:55, 3 July 2013

Tip 1509 Printable Monobook Previous Next

created 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 ;
  \:!cscope -b -i cscope.files -f cscope.out<CR>
  \: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.

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).

Comments

How do you do it in Windows. How to tell windows cmd shell to change directory to the project folder and build cscope DB there?

The directory change is easy, just use the "cd" command just like on Unix (but with backslash separators). The harder part is getting a list of files. You might be able to use dir /b /s *.c and the same for *.h, or you could use Vim to create the list of files using glob() or globpath(). Other than that, cscope itself works in pretty much the same way no matter what system you're on. --Fritzophrenic (talk) 15:46, July 2, 2013 (UTC)
But, how to pass the current working directory information to "cd", and then how to run cscope from that directory ?
Just like for any other external command. Actually from within Vim, you can just use Vim's built-in :cd command to get to the directory you want. Or use :lcd. Then use :!path\to\cscope.exe to run cscope from that directory. If you must, you can use the cmd.exe cd command instead, like :!cd some\path & path\to\cscope.exe. If you need Vim's current directory, you can use getcwd(). --Fritzophrenic (talk) 19:54, July 3, 2013 (UTC)