VI Edit Commands



The following commands are performed in command mode.
To enter command mode, press the Esc key.



Edit commands.


There are 30 some ways to edit in the vi text editor.
These are the keys I use the most.
    i     Puts you in insert mode, Before the character the cursor is on.   

    a     Puts you in insert mode, After the character the cursor is on.        

    o     Open an new line and place you in command mode Below     
          the current line the cursor is on.                  

    O     Open an new line and place you in command mode Above     
          the current line the cursor is on.                   

    ~     Changes case of a character (Upper to Lower or Lower to Upper)    

    cw    Change from the cursor to the end of the current Word. (Like type over only better)    

    C     Change from the cursor to the end of the Line.         (Like type over only better)

    r     Allows you to type over only the character highlighted by the cursor.

    R     Allows you to type over every thing on the current line.

    x     Deletes the character in front of the cursor.

    dd    Deletes the current line.

    D     Deletes from the cursor to the end of the line.

    dG    Deletes from the current line to the end of the file.

    yy    Yanks the current line of text.  (like copy in the GUI editors)

    nyy  Yanks n number of lines including the current line.

    "ayy Yanks the current line into the named buffer a.

    "anyy Yanks n number of lines into the named buffer a.

    P     Puts the last deleted or yanked line after the cursor, (under the current line).

    p     Puts the last deleted or yanked line before the cursor, (above the current line).

    "ap   Puts the line form the named buffer a after the cursor. (below the line)

    "np   Puts text from n deletion buffer after the cursor.

    
NOTE: Each time text is deleted it is saved in a delete buffer. There are nine buffers that hold
the last 9 deletions, starting with the most resent in 1. For example you delete line #3 in a file, then you add two new lines and delete line #6. Now you realize you need line #3 and don't want to type it again. In command mode type "2p to get your second oldest deletion.
    .     Repeats the last edit command weather it is an insert or delete. 
NOTE: This is a very powerful command and can make changes very fast. i.e. If you were writing some code and you had something you needed to repeat many times like the word DEFINE. All that is needed is to enter insert mode type the word once, escape to command mode and use the . to recreate you last edit, which would be the word DEFINE. The word would be repeated as many times as you type .
    u    Undo last edit.  (Undo all changes since you last hit the ESCAPE key.)
    U    Undo all changes made to the current as long as you don't leave the line.
    J    Moves the line below the cursor up, and appends it to the end of current line.
    

Back to main VI page!