Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>ctags enables two features: allowing you to jump from function calls to their definitions, and omni completion. The first means that when you are over a call to a method, hitting <code>g]</code> or <code>CTRL-]</code> will jump to the place where that method is defined or implemented. The second feature means that when you type <code>foo.</code> or <code>foo-&gt;</code>, and if foo is a structure, then a pop-up menu with field completion will be shown.</p> <p>cscope also has the first feature - using <code>set cscopetag</code> - but not the last. However cscope additionally adds the ability to jump to any of the places where a function is called as well.</p> <p>So as far as jumping around a code base is concerned, ctags will only ever lead you towards the place where the function is implemented, whereas cscope can show you where a function is called too.</p> <p>Why would you choose one over the other? Well, I use both. ctags is easier to set up, faster to run and if you only care about jumping one way it will show you less lines. You can just run <code>:!ctags -R .</code> and <code>g]</code> just works. It also enables that omni complete thing.</p> <p>Cscope is great for bigger, unknown code bases. The set up is a pain because cscope needs a file containing a list of names of files to parse. Also in vim, by default there are no key bindings set up - you need to run <code>:cscope blah blah</code> manually.</p> <p>To solve the fist problem I've got a bash script <code>cscope_gen.sh</code> that looks like this:</p> <pre><code>#!/bin/sh find . -name '*.py' \ -o -name '*.java' \ -o -iname '*.[CH]' \ -o -name '*.cpp' \ -o -name '*.cc' \ -o -name '*.hpp' \ &gt; cscope.files # -b: just build # -q: create inverted index cscope -b -q </code></pre> <p>This searches for code that I'm interested in, creates the cscope.files list and creates the database. That way I can run ":!cscope_gen.sh" instead of having to remember all the set up steps.</p> <p>I map cscope search to ctrl-space x 2 with this snippet, which mitigates the other downer of cscope:</p> <pre><code>nmap &lt;C-@&gt;&lt;C-@&gt; :cs find s &lt;C-R&gt;=expand("&lt;cword&gt;")&lt;CR&gt;&lt;CR&gt; </code></pre> <p>There's <a href="http://cscope.sourceforge.net/cscope_maps.vim" rel="noreferrer">this cscope_maps.vim plugin</a> that sets up a bunch of similar bindings. I can never remember what all the options mean, so tend to stick to ctrl-space.</p> <p>So to conclude: ctags is easier to set up and mostly works without doing much else, it's vital for omni-complete too. cscope provides more features if you have to maintain a large and mostly unknown code base, but requires more leg work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload