Programming Basics

  Home arrow Programming Basics arrow Intro to Vim
PROGRAMMING BASICS

Intro to Vim
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2003-04-02

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    This tutorial is not written to make you a guru at Vim (vi Improved) this is written for those that have shell access and need to login in and make changes to files.

    By : postalcow

    This tutorial is not written to make you a guru at Vim (vi Improved) this is written for those that have shell access and need to login in and make changes to files.

    A little bit about VI first. VI is not what you would consider a user friendly editor. But once you become comfortable with VI you will be sending me emails saying "Cow.. You Really Know Your Pies" VI is the best thing since Fillet Mignon. At the end of this down and dirty tutorial I will give you some sites to get more information on VI.

    In this tutorial you'll be working in two modes Editing and Command.

    Editing, Self explanatory. This is the mode that will give you the ability to edit the file.

    Command, This mode is where commands are given to VI to do such things as writing, saving and quitting. If you get the urge to learn more about VI you can turn on text coloring, auto indentation, folding features and 100's of others.

    Starting VI and opening a file.

      vi somefile.php

    To start editing a file you need to enter one of the edit modes. These commands are case sensitive, 'i' is not the same as 'I'. Also, always remember <esc> takes you out of an editing mode.

    Lets dig in to basic VI

        1) To enter VI, type: vi somefile.xxx &lt;Enter&gt;
        2) To go into the insert mode type: i
        3) Enter some text. Postal I love using VI
        4) Press the &lt;esc&gt; key to leave insert mode
        5) Save the file type &lt;esc&gt; :wq  (that means write and quit)

    Moving around in VI.

    You can use your cursor keys <left> <down> <up> <right> or h j k l for left,down,up,right.

    In command mode you can use the following commands wherever your cursor is.

        x   deletes a character.

        dd  deletes the whole line the cursor is on.

        r   replaces a character

    Displaying Line numbers
        &lt;esc&gt; :set nu         Turns on line numbering

        &lt;esc&gt; :set nonu     Turns off line numbering

    Quitting VI
         :wq    Write, then quit
      
         :q     Quit (will only work if file has not been changed)
      
         :q!    Quit without saving changes to file

    That's the Basics. Here are a few advanced commands.

    Going from command mode to text mode
            i       Insert text before current character
      
            a       Append text after current character
      
            I       Begin text insertion at the beginning of a line
      
            A       Append text at end of a line
      
            o       Open a new line below current line
      
            O       Open a new line above current line

    Command mode commands
            .       Repeat last command
      
            n.      Repeat last command n number of times
      
            J       Join next line to current line
      
            u       Undo last single change
      
            U       Restore current line

    Useful Sites

    The official siteAn introduction to display editing with VIA good reference manual


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Programming Basics Articles
    More By Codewalkers

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP
    - Calendar Construction with PHP
    - PHP`s Calendar Package
    - Getting Modified Versions and Correct Dates ...
    - Combining Date Functions in PHP
    - Using PHP for Date and Time in Programming
    - More Exception Handling with PHP
    - Exception Handling in PHP
    - Error Logging and Handling Exceptions
    - Configuration Directives for Error and Excep...
    - Error and Exception Handling
    - Python Modules for Games


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap