A Useful Subset of vi Commands 1. Start a) vi filename (std. editing) b) view filename (read-only) 2. End (must be in command mode) a) Quit without saving i) :q (quit--if no changes have been made) ii) :q! (force a quit without saving--even if changes have been made) b) Quit and save i) :wq (write and quit) ii) :wq! (force a write over a read-only file and quit) iii) :ZZ iv) :x 3. Modes a) Command mode i) esc switches from Insert to Command Mode b) Text entry or insert mode i) Any of the text entry commands switches from Command to Insert Mode 4. Move (when in command mode) a) Simple i) cursor keys ii) h, j, k, l keys (left, down, up, right) b) Jump i) 0 (beginning of line) ii) $ (end of line) iii) :1(line one of file) iv) :n (line n of file) v) :$ (last line of file) 5. Text Entry (Insert Text) Commands a) Insert i) i (insert typing here, i.e. insert before cursor) ii) I (insert typing at beginning, i.e. insert at beginning of line) b) Append i) a (append typing here, i.e. insert after cursor) ii) A (append typing at end, i.e. insert at end of line) c) Replace i) r (replace the single character at the cursor) ii) R (start replacing at the cursor and keep going to the right) 6. Cut and Paste Commands a) dd (cut current line to the buffer) b) ndd (starting at the current line, cut n lines to the buffer, eg 5dd) c) P (paste from the buffer above the current line) d) p (paste from the buffer below the current line) 7. Find Commands a) /string (find and place the cursor under the first appearance of "string" occurring after the current cursor position) b) / (find the next occurrence of the search string-- Note: will wrap around back to beginning) c) n (find the next occurrence of the search string) 8. Miscellaneous Commands a) u (undo last command) b) J (join end of current line with next line) c) x (delete the character at the cursor)