VIM -- QUICK AND DIRTY ---------------------- Starting vim Whatever you type in INSERT MODE vim is entered into your file. COMMAND Starting vim with a file MODE is used for moving around, vim filename deleting, saving, quitting, etc. Insert (go to INSERT MODE) In INSERT MODE i -- insert before cursor DEL -- erase previous character a -- insert after cursor (append) CTRL-U -- erase to start of o -- open a new line below insert or line O -- open a new line above ESC -- go to COMMAND MODE All commands below are performed in COMMAND MODE Deleting Saving and quitting x -- erase character at cursor :w -- save (write) file dd -- delete line :q! -- quit without saving ndd -- delete n lines (eg, 10dd) :wq -- save and quit dw -- delete word ZZ -- same as :wq Moving around Undo h or left-arrow -- move left u -- undo last command l or right-arrow -- move right j or down-arrow -- move down Miscellaneous k or up-arrow -- move up J -- join this line with next $ -- go to end of line % -- find matching ( ) { } ^ -- go to beginning of line CTRL-L -- redraw messy screen w -- move forward one word /xyz -- find word "xyz" CTRL-F -- forward one page CTRL-B -- back one page Useful options nG -- go to line n (eg, 10G) :set ai -- autoindent G -- go to last line :set nu -- show line numbers CSE12 Additions: Cutting and Pasting One Line yy -- copy a line to "clipboard" p -- put or "paste" copied line to current cursor line. Blocks of Lines from COMMAND MODE, type ":#1,#2 co #3" (the colon is needed to give the block command) replacing #1, #2, and #3 with real numbers. #1 represents the start line of the block of line you want to cut or copy, #2 represents the end line, and #3 represents the line you want to move the BEGINNING of that block to. copying -- #1,#2 co #3 -- moves a copy of the lines without deleting. moving -- #1,#2 mo #3 -- moves the actual code from the original lines. deleting -- #1,#2 de -- there is no #3, because you do not put deleted lines onto any other line, they just vanish.