Linux Command vi vim — Unix Command gvim

Focused casual businessmen working at computer in sunny office

Tom Merton/Getty Images



  • 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 mode Remarks
<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.