Linux

Linux vi commands

Quick Tutorial for Editor vi

  1. Invoking vi
  2. If you write a command

    vi my_file

    you will see the screen with a column of tildes. The editor vi is now in so called command mode.

    The screen looks like:

    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    
    
    The two basic commands are the following:

    i Insert text to the left of cursor
    a Insert text to the right of cursor

    Since you are at the beginning of an empty file it does not matter which of these you type. Write a text: 

           Thank you for your kind invition.
      I will be happy to see you on Ocotober 30th.
      I will look forward to meet you and
      hearing about your proposals.     .

                                          Yours sincerely

                                                   Kenny R.            .                                          

  1. Cursor Movements Commands
  2. You need to be in the command mode. If you do not now what mode is actual, press the buttom esc. This keystroke always turns the editor in the command mode. Then you can move along the screen if you keystrokes the button:

    Keystroke of Doing
    h Cursor is moved one space to the left
    j Cursor is moved one line down
    k Cursor is moved one line up
    l Cursor is moved one space to the right

  3. Deleting Text
  4. If you are in command mode then

    Keystroke of Doing
    x Delete one character at the cursor
    dd Delete one line where the cursor is placed

    If you are in command mode and you will write

    :set smd nu

    (where smd means Show MoDe and nu means NUmber),
    you will now see the mode at the right down corner (usually) and all lines are numbered.

    1  Dear Mr Fisher,
    2
    3      Thank you for your kind invition.
    4  I will be happy to see you on Ocotober 30th.
    5  I will look forward to meet you and
    6  hearing about your proposals.     .
    7
    8                                      Yours sincerely
    9
    10                                               Kenny R.
    
    
    
    
    
    
    
    
    						   INPUT MODE
    

    Now go to the 6th line - move the cursor underneath the number 2 press letter x. Pres i and write number 3

  5. File Saving
  6. You must be in command mode. You can use then several tricks to save the file:

    Keystrokes Doing
    :x Write file to the disk and finish
    ZZ Write file to the disk and finish
    :w Write file to the disk and continue

  7. Replace Mode
  8. Very useful is so called replace mode which enables overwrite the existing text.

    Keystrokes Doing
    :r Replace one character over the cursor
    :R Overwrite text until the next action (e.g. keystroke of esc)

Google

Sections:


LinuxIdiot Home
Linux vi commands
Linux Basic Commands
Directory Structure
Choosing Linux

 Site Map | All rights reserved 2007