Linux Command vi vim - Unix Command gvim

Focused casual businessmen working at computer in sunny office
Caiaimage/Tom Merton / Getty Images


% vi [options] [file ..]


  • The "vi" text editor is not recommended for newbies.
  • To exit vi (no changes saved) use these five characters: <ESC>:q!<Enter>.
  • vim: Modern Linux distributions use vim (="vi improved") in place of vi, and vim is somewhat better than the original vi.
  • gvim: The GUI version of vi is also available: type gvim in an X terminal.
  • The most important thing to understand about vi is that is a "modal" editor, i.e., it has a few modes of operation among which user must switch. (The same keystrokes have different effects in different modes.) The quick reference is below, with the 4 essential commands in red.

    The commands to switch modes:



    Enters the modeRemarks
    <ESC>command mode(get back to the command mode from any editing mode)
    i"insert" editing mode(start inserting before the current position of the cursor)

    NOTE: Do not press any other keys in the Command Mode. There are more commands and modes in the Command Mode!

    Copying, cutting and pasting (in the command mode):

    • v start highlighting text. Then, move the cursor to highlight text
    • y copy highlighted text
    • x cut highlighted text
    • p paste text that has been cut/copied

    Saving and quitting (from the command mode):

    • :w write (=save)
    • :w filename write the contents to the file "filename"
    • :x save and exit
    • :q quit (it won't let you if changes not saved)
    • :q! quit discarding changes (you will not be prompted if changes not saved)



    Starts vi with the default settings and opens file

    Important: Use the man command (% man) to see how a command is used on your particular computer.