Administration
  Home arrow Administration arrow Page 7 - Vi 201
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ADMINISTRATION

Vi 201
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2000-05-11

    Table of Contents:
  • Vi 201
  • Liar, Liar...
  • Re-thinking Relativity
  • Sweet Revenge
  • The Shell Game
  • First Aid 101
  • An Indent In Time...
  • Exit Flootburger

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    Vi 201 - An Indent In Time...
    (Page 7 of 8 )

    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

    :set autoindent
    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

    :set cindent
    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:

    if(time == 13) { lunch(); } else if (time == 22) { if (day == "Friday") { echo "Apple pie for dessert!": } else { echo "Oh no, not lasagna again!"; } }
    and here's the "after" picture:

    if(time == 13) { lunch(); } else if (time == 22) { if (day == "Friday") { echo "Apple pie for dessert!": } else { echo "Oh no, not lasagna again!"; } }
    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

    :syntax on
    while

    :syntax off
    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:

    $ ctags *.c
    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

    ^-] [that's Ctrl-square-brace]
    Vi will automatically load the file containing the function definition, and display it to you. To go back to the original file, use

    ^-T [that's Ctrl-T]
    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.

    More Administration Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    ADMINISTRATION ARTICLES

    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization
    - Advanced Concepts on Dealing with Files and ...
    - Dealing with Files and Filesystems
    - More Hacks for the User Environment in BSD
    - Personalizing the User Environment in BSD
    - Customizing the User Environment in BSD




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway