~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lesson 1 SUMMARY STARTING VIM: At the shell prompt, type: vim FILENAME THE KEY: Gets out of Insert mode (back to Normal mode) Cancels an unwanted and partially completed command Type over and over if once is not enough!! MOVING AROUND: arrow keys or the hjkl keys h (left) j (down) k (up) l (right) EXITING VIM: :q! to trash all changes. :wq to save the changes. DELETING CHARACTER UNDER CURSOR x To delete character under cursor INSERT/APPEND TEXT: i type inserted text insert before the cursor A type appended text append after the line ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lesson 2 SUMMARY dw To delete from the cursor up to the next word d$ To delete from the cursor to the end of a line dd To delete a whole line 2w To move 2 words over (2 could be any number) 4b To move back 4 words (4 could be any number) 0 To move to the start of the line (that's a zero) $ To move to the end of the line UNDO: u To undo the previous action (lowercase u) U To undo all the changes on a line (capital U) REDO: CTRL-R To undo the undo's ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lesson 3 SUMMARY p To put back text that has just been deleted. This puts the deleted text AFTER the cursor (if a line was deleted it will go on the line below the cursor). r To replace the character under the cursor (type r and then the character you want to have there.) ce To change from the cursor to the end of the word c$ To change from the cursor to the end of the line. c3e To change from cursor to end of words over (3 could be any number) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lesson 4 SUMMARY DISPLAY FILE INFO: CTRL-G Displays location in the file and the file status MOVING AROUND FILE: G Move to the end of the file 5G Move to line 5 of file. (could be any number) gg Move to the first line. '' Move to previous line (that is two single quotes) CTRL-O Move back to older positions (a "back" button) CTRL-I Move ahead to newer positions (a "fwd" button) SEARCHING /phrase Searches FORWARD for the phrase ?phrase Searches BACKWARD for the phrase n Repeats previous search in same direction N Repeats previous search in opposite direction PARENTHESIS MATCHING % while the cursor is on a (,),[,],{, or } goes to its match SUBSTITUITION :s/old/new To substitute new for the first old in a line :s/old/new/g To substitute new for all 'old's on a line :2,7s/old/new/g To substitute phrases between lines 2 and 7 (or any numbers) :%s/old/new/g To substitute all occurrences in the file :%s/old/new/gc To ask for confirmation each time add 'c' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lesson 5 SUMMARY EXECUTE EXTERNAL COMMAND: :!ls Shows a directory listing :!rm FILENAME Removes file FILENAME :!COMMAND Executes the COMMAND in the shell (COMMAND is any linux command) :w FILENAME writes the current Vim file to disk with name FILENAME v motion :w FILENAME saves the Visually selected lines in file FILENAME :r FILENAME retrieves disk file FILENAME and puts it below the cursor position :r !ls reads the output of the ls command and puts it below the cursor position ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lesson 6 SUMMARY o Opens a line BELOW the cursor and start Insert mode O Opens a line ABOVE the cursor a Inserts text AFTER the cursor A Inserts text after the end of the line e Move to the end of a word y Yank (copy) text p Put (paste) text that was just yanked. R Enters Replace mode until is pressed :set xxx Sets the option "xxx". Some options are: 'ic' 'ignorecase' ignore upper/lower case when searching 'is' 'incsearch' show partial matches for a search phrase 'hls' 'hlsearch' highlight all matching phrases You can either use the long or the short option name. Prepend "no" to switch an option off: :set noic :set syntax=on Turns on code syntax hilighting, when available :set syntax=off Turns off code syntax hilighting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lesson 7 SUMMARY :help Opens a help window (or press or ) :help cmd Find help on cmd CTRL-W CTRL-W Jump to another window :q Closes the help window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~