Skip navigation.
Home

Vim is Great for Reading Code

Vim has a couple features to make it easy to read C (and PHP and Perl) code.

First is the "go to file" feature. If you move the cursor onto a file name, and type gf, you'll be taken to that file. To return to the previous file, press Control-o. The file opens are kept on a stack, so you can drill down into file, and climb back out. This is useful for reading code with "includes".

Second is the "tags" feature. If you have a body of code written in C, you can use the "ctags" command to generate an index of function definitions. This is stored in a file named "tags" in the root directory. When you move the cursor onto a word, and press Control-], it looks up the word in tags, and opens up the file with the definition, and puts the cursor at the definition. The tags are kept on a stack, and you can back out of the file by pressing Control-t. This is useful if you're reading a header file or some code, and want to know what a function does.

The exuberant-ctags package (on Debian) also known as etags, is a ctags that works for PHP, Perl, Java and a lot of other languages.

Generally, I'll create a script to refresh the tags file, and make sure ALL the files I'm using are included in the database. As the project grows, I re-run the script to rebuild the db. Simple.

Reply

  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul> <p> <br> <div> <pre> <code> <img><h1><h2><h3><h4> <blockquote>
  • Lines and paragraphs break automatically.

More information about formatting options