5.vi_editor

Upload: kuldeep-batra

Post on 06-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 5.vi_editor

    1/3

    Practical 5

    INTRODUCTION TO vi EDITOR

    vi is a powerful editor with many features. It can handle very large files much easier than

    a program like Microsoft Word. Unlike Word, vi is only a TEXT EDITOR and you

    cannot include graphics or fancy fonts in your file.

    Although there are lots of different commands in vi, it is possible to get started using vi

    knowing only a small subset of them. As you feel more comfortable with vi, you can

    learn the more advanced features.

    vi has 3 modes:

    1. write mode, used for entering text2. command mode and

    3. command line mode, used for entering commands to vi.

    Remember, in vi, the mouse cannot be used to issue editor commands or move the cursor.

    Write Mode

    When you first enter the editor, you are in the command mode. To enter the write mode,type the lettera for append. This is one of the four possible commands for entering the

    write mode. vi is Case Sensitive. Lower case commands are different from upper case

    commands.

    Command Mode

    You are in command mode whenever you hit esc to leave the write mode. In commandmode, you can move the cursor anywhere in the file.

    The x key deletes individual characters, while dd deletes an entire line. To enter the

    insert mode type the i key. When you're done inserting, hit the "esc" key to return to the

    command mode.

    Command-Line Mode

    Command-line mode is used for such things as writing changes and exiting the editor. To

    enter command-line mode, type : while in command mode. The : will now appear at the

    bottom of the screen and the command which you type will appear on that line.

  • 8/3/2019 5.vi_editor

    2/3

    1. How to create a new file or modify an existing file:

    EXAMPLE:

    % vi practice

    In this example, the new file "practice" is created if it doesn't already exist.

    The screen will look like this after opening a new file entitled, "practice".

    ===========================================================

    ==

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    "practice" [New File]

    ===========================================================

    ==

    The Edit Mode

    Once in vi, you are placed in the command mode. You cannot enter text in this mode. If

    you try, the letters you try to type will not appear on the screen. This is because ordinaryletters are interpreted as commands.

    You must enter the edit mode to type text.

    To do so, use one of the following commands. The vi text editor is case sensitive, which

    means the same letters in upper and lower case have different command responses.

  • 8/3/2019 5.vi_editor

    3/3

    2. How to add information to a file:

    What to Type Result

    a append after the cursor

    i insert before the cursor

    The "esc" key must be used to end any of the above commands or to begin any of the

    following commands (depending on which way you look at it). You must also hit the

    "esc" key prior to any cursor movement. When in doubt, hit the "esc" key and proceed.

    3. How to delete information from a file:

    What to Type Result

    x deletes the character the cursor is under

    dd deletes the line the cursor is on

    4. More edit commands

    In the command mode, it is possible to move the cursor up, down, left or, right by using

    the arrow keys on the keyboard. However, no matter what type of keyboard you have, itis possible to use the vi commands, h, j, k, and l, all in lowercase, to control the cursor.

    These commands move the cursor as follows:

    What to Type Result

    j moves the cursor up one line

    k moves the cursor down one line

    h moves the cursor backwards on a line

    l moves the cursor forward on a line

    To cut and paste, I usually use the Mac commands instead of the vi commands. These

    work with NCSA Telnet. Just select the text to copy with your mouse, then move the

    cursor using the arrow keys (not the mouse) over to the area you want to paste the text,then make sure you are in the "insert" or "append" mode and then paste the text using the

    Macintosh command (Command-v).