Help:Vi basic commands

From CECS wiki
Jump to navigation Jump to search

<<Back to Help:vi

Vi is the traditional unix editor. It is run by typing

vi <file to edit> 

Vi has two modes of operation, command mode and insert mode. Insert mode is used to type text directly into the document. Command mode (the mode activated when you load vi) allows you to use keys for navigating and manipulating the document. The keys are:

  • h - Move left (Arrow keys also work)
  • j - Move down
  • k - Move up
  • l - Move right
  • Ctrl-F - Move one screen forward
  • Ctrl-B - Move one screen backwards
  • G - Go to the end of the file
  • o - Opens a new line and puts you in insert mode.
  • i - Enter insert mode at the current cursor position.
  • A - Insert at the end of the line.
  • esc - Exit insert mode and go back to command mode.
  • x - Delete the character you are on.
  • dd - Delete the whole line you are on.
  • ZZ - Save changes and exit.
  • :q - Exit if no changes have been made.
  • :q! - Exit if changes were made but you don't want them saved.
  • :w - Write the file to disk without exiting.

Note: Arrow keys do not work in insert mode and may cause random letters to come up on your screen. In order to change positions you must exit insert mode (with esc) and then use the arrow keys to move.

These are the basics and should get you through most jobs that need to be done.