Pages

Saturday, January 8, 2011

Basic "vi" Editor Commands

All commands in vi must be preceded by pressing the “Escape” key. Most commands are case sensitive.
CURSOR MOVEMENT
  • Arrow Keys -> Generally work as expected
  • Page up/down -> Generally work as expected
  • nh -> Left n spaces (n indicates a number and is optional)
  • nj -> Right n spaces (n indicates a number and is optional)
  • nk -> Up n spaces (n indicates a number and is optional)
  • nl -> Down n spaces (n indicates a number and is optional)
  • ^F -> Forward one screen (^ indicates the “Control” key)
  • ^B -> Back one screen (^ indicates the “Control” key)
  • 0 -> (Zero) beginning of line
  • $ -> End of line
  • H -> Beginning of top line of screen
  • L -> Beginning of last line of screen
  • :1 -> Beginning of file
  • G -> End of file
INSERTING TEXT
  • i -> Insert text before cursor
  • a -> Append text after cursor (does not overwrite)
  • I -> Insert text at beginning of line
  • A -> Append text at end of line
  • r -> Replace the character under the cursor with next character typed
  • R -> Overwrite characters until end of line
  • o -> (Lowercase “o”) new line after the current line
  • O -> (Uppercase “O”) new line before the current line
DELETING TEXT
  • dd -> Deletes current line
  • ndd -> Deletes next n lines
  • D -> Deletes from cursor to end of line
  • x -> Deletes current character
  • X -> Deletes previous character
FILE MANIPULATION
  • :w file ->  Writes changes to file (file is optional, default is current file)
  • :w file -> Overwrites file (file is optional, default is current file)
  • :f -> Name renames current file to name
  • :q -> Quits edit session when no changes have been made
  • :q! -> Quits edit session and discards changes
  • :wq -> Writes changes to current file and quits edit session
MISCELLANEOUS
  • u -> Undo the last command made to a line
  • . -> Repeat the last command made to a line
  • nyy -> Yank n lines to buffer (n indicates a number and is optional)
  • ynw -> Yank n words to buffer (n indicates a number and is optional)
  • p -> Puts yanked or deleted text after cursor
  • P -> Puts yanked or deleted text before cursor
  • :r file -> Inserts file at current cursor position

No comments:

Post a Comment