Site Administration Page 7 - Vi 201 |
See Also: Finally, if you're a programmer, vi comes with a number of features that you should find useful. Here are some tips that might help you the next time you sit down to code The Next Big Thing. 1. Let vi indent your code for you. Try and watch as vi automatically indents nested blocks of code like loops and conditional statements. C programmers might also like to take a look at which offers some additional indenting styles. 2. In case you forget to turn auto-indenting on, all is not lost. Simply select the lines of code you wish to indent, and hit Vi will do its best to indent the code correctly for you. To illustrate the power of this trick, here's a "before" picture: and here's the "after" picture: 3. Newer versions of vi comes with "syntax highlighting" - the ability to highlight program code in different colours. To turn this feature on, simply type while will turn it off. Vi currently supports most popular programming languages - your distribution should come with syntax files for C, C++, HTML, Java, Perl, PHP and other common languages. 4. Vi also comes with the very useful "ctags" program, which can be used to create an index of classes, function definitions, variable declarations and methods for C, C++ and Java source code. This index, also known as a "tag" list, can be used by vi and other text editors to assist you in quickly locating sections of your source code while programming. To use vi's tag features, it's first necessary to create a tag file - simply change to the directory containing your source code and run the "ctags" program on the files you wish to index, like this: You should now have a file named "tags" in that directory. Now open one of your C files, and scroll down until you locate a function call. Position the cursor over that function call, and hit Vi will automatically load the file containing the function definition, and display it to you. To go back to the original file, use This comes in very handy when your code is scattered across multiple files, and you just can't remember what the function popeye_loves_spinach() does. This article copyright Melonfire 2000. All rights reserved.
blog comments powered by Disqus |