Two plugins I can’t imagine Vim without
UltraSPARC port improvement March 19th, 2009I like Vim. Especially for editing C
code. I would like to introduce two extensions I especially like.
The first one is a Vim binding for Cscope. Cscope is a tool which makes an index from your source tree and uses the index to quickly tell you
- where a function with a given name is defined,
- where a function with a given name is called from,
- where a given string occurs in your source files,
- etc.
Cscope can be used either as a standalone command-line application, or via a binding into a text editor. Using the Vim binding for Cscope is very easy. Imagine you would like to get a list of all places from which a function is called. All you must do is to move the caret above the function name and press a certain key combination (Ctrl+\ c
). You can use Vim command line as well (:cs find c my_function
). Having the list, you just type the number of the occurrence you are interested in and Vim will jump to the occurrence.
Since this is a blog about HelenOS, I will mention how to use Cscope for HelenOS development. In our Makefile we define a target called cscope. The target creates the Cscope index. Just cd
to the HelenOS root directory and type
make cscope
and an index file called cscope.out
will be generated for you. Now when you start Vim from the HelenOS root directory, it will automatically connect to Cscope so that the above key shortcuts (or Vim commands) can be used. A tutorial on using Cscope with Vim can be found at http://cscope.sourceforge.net/cscope_vim_tutorial.html.
The second Vim extension I appreciate is called Mini Buffer Explorer (http://vim.sourceforge.net/scripts/script.php?script_id=159). I don’t know exactly what is meant by ‘buffer’ in Vim… So let me simply say that this extension allows you to switch between opened files using tabs. It is especially useful in combination with the Cscope binding. If you jump from a location in file a.c
to some location in file b.c
, the latest edit location in file a.c
will not be lost. Instead, two ‘tabs’ will be shown above the edit area: [a.c]
and [b.c]
. When you are done with investigating the contents of the b.c
file, you will just switch back to a.c
using the tabs.
With the Mini Buffer Explorer extension you can have as many concurrently opened files in one running Vim instance as you want. To open a new file, just use a standard Vim command :E
. To close a current file, use the :bd
command (:q
would close Vim completely).
Your favorite Linux distribution will probably contain a package called ‘cscope’. Installing the two extensions is just a matter of copying a couple of files to the ~/.vim/plugin
directory.
Leave a Reply
You must be logged in to post a comment.