Tuesday 23 February 2016

The VI Editor

The vi editor (stands for visual editor) is a screen editor which is available on almost all Unix systems. Once you have learned vi, you will find that it is a fast and powerful editor. There is also a improved version of VI called VIM.

Vi editor works on different UNIX flavors. It is fast and powerful undo features. There are few limitations also there it is less user friendly, high case sensitive and keystroke could have more than one meanings.

Working modes of VI editor :

Command Mode : Keys are interpreted as commands.
Insert Mode         : Keys are interpreted as data
Escape Mode       : Keys are interpreted for saving/exiting purposes





Whenever a particular file is opened using the vi editor, it opens up in the Command mode. In this mode, the keyboard-character represents command and not data. A user cannot enter the data in the Command mode. The user has to switch over to the insert mode to enter the data. This could be done using the letters like "a", "i", etc. Once the user is in insert mode, the data could be entered. The user could switch back to the Command mode. For saving or exiting the application the user has to get into the Escape mode by pressing "Esc" key.

General Startup
 
    To use vi: [vi filename] + Enter
    To exit vi and save changes:    Esc Key+[ ZZ   or  :wq ] + Enter
    To exit vi without saving changes:    [ Esc Key + :q! ] + Enter
    To enter vi command mode:    [Esc]

Cursor Movement

 
    h       move left (backspace)
    j       move down
    k       move up
    l       move right (space-bar)


    [return]   move to the beginning of the next line

    $       last column on the current line
    0       move cursor to the first column on the current line
    ^       move cursor to first non blank column on the current line
    w      move to the beginning of the next word or  punctuation mark
    W     move past the next space
    b       move to the beginning of the previous word  or punctuation mark
    B      move to the beginning of the previous word, ignores punctuation

        e       end of next word or punctuation mark
        E      end of next word, ignoring punctuation
        H      move cursor to the top of the screen
        M      move cursor to the middle of the screen
        L       move cursor to the bottom of the screen

Screen Movement
 
       G        move to the last line in the file
       gg        move to the first line in the file
       xG       move to line x


       z+       move current line to top of screen
       z        move current line to the middle of screen
       z-       move current line to the bottom of screen

       ^F       move forward one screen
       ^B       move backward one line

       ^D       move forward one half screen
       ^U       move backward one half screen

Inserting
 
       i        insert before cursor
       a        append after cursor

       A        append at end of line
       O        open line above cursor and enter append mode
       r        replace character under cursor with next character typed
       R        keep replacing character until [esc] is hit

Deleting
 
    x       delete character under cursor
    dd      delete line under cursor

    dw      delete word under cursor
    db      delete word before cursor

Copying Code
 
    yy      (yank)'copies' line which may then be put by the p(put) command. Precede with a count
              for multiple lines.

Put Command
 
        Brings back previous deletion or yank of lines,words, or characters
        P       bring back before cursor
        p       bring back after cursor

 Find Commands
 
    ?       finds a word going backwards
    /       finds a word going forwards


    f       finds a character on the line under the cursor going forward
    F       finds a character on the line under the cursor going backwards

    t       find a character on the current line going forward and stop one character before it
    T       find a character on the current line going backward and stop one character before it

    ;        repeat last f, F, t, T

Miscellaneous Commands
 
    ^G    display current line number
    .        repeat last command
    u       undoes last command issued
    U      undoes all commands on one line

Line Editor Mode
    Any commands form the line editor ex can be issued upon entering line mode.

    To enter: type ':'
    To exit: press[return] or [esc]

READING FILES
    copies (reads) filename after cursor in file currently editing

    :r filename

WRITE FILE
    :w     saves the current file without quitting

MOVING
    :#    move to line #
    :$    move to last line of file

SHELL ESCAPE
    executes 'cmd' as a shell command.
    :!'cmd'






                         **********************END************************

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...