OHSU Library
How To: Use UNIX Text Editor - vi

There are three basic modes. Command mode, Insert mode, and Last line.

Command Mode:
When you first enter vi you are in command mode. You can move around the document, perform simple editing functions, and enter Last line commands.


      
POSITIONING IN A FILE:
         k      move up one line.
         j      move down one line.
         h      move left a character.
         l      move right a character.

         1G     move to first line in file.
          G     move to last line in file.
         ^f     move forward one screenfull.
         ^b     move back one screenfull.

DELETE COMMANDS:  
         dd     delete line cursor is on.
         3dd    delete next three lines.
         x      delete a character cursor is on.
         D      delete from cursor to end of line.


COPY AND PASTE:    
         yy     copy current line into buffer.  (use delete commands to cut)    
         4yy    copy next four lines into buffer.
         p      copy lines in buffer on line below current line.


UNDO, REDO, REPLACE:  
         u      Undo the last change.
         .      repeat the last change.
         r      replace character cursor is on.

JOIN TWO LINES:
         J      with cursor at end of line, join bottom line to current line.

Insert Mode: There are several ways to get into insert mode. Once in insert mode you can enter characters line by line (line buffer holds 256 char). Characters can be deleted by using the delete or backspace key but you can only delete characters on the current line and within the point of insert. To terminate insert mode press the ESC key (back in command mode).

INSERT WITHIN A LINE:
        i       insert before character cursor is on.
        a       append after character cursor is on.
        A       append after last character on line.
       
OPEN A LINE:        
        o       open line below current line.
        O       open line above current line.
 
TYPEOVER:
        R       replace characters from current cursor position until ESC.

LAST LINE:
        These commands take place on the last line of the screen (window) when you enter a ":" or "/" while in command mode.  


THESE COMMANDS ALLOW FOR FILE MANIPULATION AND FILE SEARCHING:


SEARCH:                 
        /pattern       search forward from current cursor position for first occurrence of pattern.

SAVE:
        :w              writes changes to file.


       :wq              writes changes to file and quits edit session

ABORT:
        :q!             Aborts edit session without making changes.


GOTO LINE:
        :4              puts cursor on line 4.

READ IN FILE:
        :r<filename>     read file in and append to line below cursor.


GLOBAL SEARCH AND REPLACE:    
        :1,$s/blue/green/g
                        from line 1 to end of file, replace every occurrence of blue with green.

IN GENERAL:

      Press j to go down to the line below keywords to type your message.

      Press i to invoke insert mode and type your message.

      Press esc ZZ (two upper case z's) to save the message when finished.

      Press s to send the message.



Back to the top

OHSU Library 
navigation bar OHSU Library Home Need help? Ask a Librarian Search the OHSU 
Library Web site Contact us Catalog Databases Journals Electronic Books Course Reserves Services Request forms Interlibrary Loan Software licensing Off-campus access About the Library Hours/Locations Staff/Departments OGI S&E Library ONPRC Library What's New Listserv 
signup Consumer Health Historical Collections and 
Archives Digital Resources Library
Last updated September 19, 2008 by the OHSU Library Web Managers. Please send comments, questions, and reports of problems through the Library's customer support form.