"vi and You : An Instructional Handout" ======================================= vi - to edit a file called vi - brings up editor with no filename :q :wq ZZ :q! - to exit vi (several ways) 1) :q - allows you to exit if no changes were made 2) :wq - writes changes to the file, then exits 3) ZZ - writes changes to the file, then exits 4) :q! - exits the edit session, WITHOUT saving changes :w - to save changes without leaving edit session :<#1>,<#2> w - save section to a new file called Moving around in COMMAND MODE ----------------------------- h - left j - down k - up l - right ^b - back one screen ^f - forward one screen ^g - show current line number :set number - display line numbers along left side of screen :set nonumber - turn off line numbers along left side of screen :<#> - goto line number <#> <#>G - goto line number <#> 1G - goto first line $G - goto last line :$ - goto last line G - goto last line ^ - goto start of current line $ - goto end of current line u - undo last change made U - undo all changes made to current line COMMAND mode <--> EDIT mode --------------------------- i - insert before current position (EDIT mode) I - insert at beginning of current line (EDIT mode) a - append after current position (EDIT mode) A - append at end of current line (EDIT mode) o - open new line below current line (EDIT mode) O - open new line above current line (EDIT mode) - return to COMMAND mode Edit commands ------------- x - delete current character dd - delete current line d$ - delete to end of current line dw - delete to end of current word r - replace current character with next character typed R - overwrite characters until is typed Searching & Replacing --------------------- / - forward search for ? - backward search for :<#1>,<#2> s///g - replace all occurrences of the old string in the range between the two line numbers with the new string Moving & Copying ---------------- :<#1>,<#2> t <#3> - copy text between <#1> and <#2> to line <#3> :<#1>,<#2> m <#3> - move text between <#1> and <#2> to line <#3> {NOTE : "." means "current line" "$" means "last line" here} :r - brings in the file at the cursor Copyright 1996 - Evan Golub