VIM -- QUICK AND DIRTY

PLEASE READ THIS MESSAGE CAREFULLY TO AVOID LOSING YOUR WORK!!!

Starting vim
         vim
Starting vim with a file
         vim filename


Insert (go to INSERT MODE)
         i -- insert before cursor
         a -- insert after cursor (append)
         o -- open a new line below
         O -- open a new line above

Whatever you type in INSERT MODE
is entered into your file. COMMAND
MODE is used for moving around,
deleting, saving, quitting, etc.


In INSERT MODE
         DEL -- erase previous character
         CTRL-U -- erase to start of insert or line
         ESC -- go to COMMAND MODE

All commands below are performed in COMMAND MODE

Deleting
         x -- erase character at cursor
         dd -- delete line
         ndd -- delete n lines (eg, 10dd)
         dw -- delete word


Moving around
         h or left-arrow -- move left
         l or right-arrow -- move right
         j or down-arrow -- move down
         k or up-arrow -- move up
         $ -- go to end of line
         ^ -- go to beginning of line
         w -- move forward one word
         CTRL-F -- forward one page
         CTRL-B -- back one page
         nG -- go to line n (eg, 10G)
         G -- go to last line

Saving and quitting
         :w -- save (write) file
         :q! -- quit without saving
         :wq -- save and quit
         ZZ -- same as :wq


Undo
         u -- undo last command

Miscellaneous
         J -- join this line with next
         % -- find matching ( ) { }
         CTRL-L -- redraw messy screen
         /xyz -- find word "xyz"

Useful options
         :set ai -- autoindent
         :set nu -- show line numbers


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.