Vim Cheatsheet

Lesson 1

Key Function
    h Move Left.
    l Move Right.
    j Move Down.
    k Move Up.
    :q Close file.
    :q! Close file without saving.
    :w Write.
    :wq Write and quit.
    x Delete Character at the Cursor.
    i Insert at cursor.
    I Insert at beginning.
    a Append at cursor.
    A Append at end of line.

Lesson 2

Key Function
    dw Delete word.
    $ Go to the end of the text.
    w Next Word.
    b Previous Word.
    e Go the end of the word.
    0 Go to beginning of the line at the very start.
    ^ Go to beginning of the line at the starting text.
    d$ Delete to the end of line.
    2w Go two words forward.
    3e Go to the end of 3rd word.
    d2w Delete two words.
    dd Delete entire line.
    2dd Delete two entire line.
    u Undo last change.
    U Undo changes on entire line.
    Cntrl + r Redo changes.

Lesson 3

Key Function
    p Paste after Cursor.
    P Paste before Cursor.
    cw Change word.
    r Replace character under the cursor.
    c$ Change to the end of line.
    c2w Change 2 words.

Lesson 4

Key Function
    :50 Go to line no 50.
    G Go to the last line.
    gg Go to the first line.
    /waldo Search for waldo.
    n Go to next search result.
    N Go to previous search result.
    ?carman Search carman in reversed.
    ctrl + o Jump to previous location.
    ctrl + i Jump to next location.
    % Go to next matching pranthesis or brackets.
    :%s/bad/good Replace bad with good in current line.
    :%s/hi/bye/g Replace hi with bye in whole document globally.
    :%s/x/y/gc Replace x with y and ask for confirmations.

Lesson 5

Key Function
    v Open visual mode.
    V Open visual select lines.
    vw Visual select word.
    vwx or vwd Visual select and then delete the word.
    :w readme.txt To write the current data as readme.txt.
    :!ls Run ls shell command.

Lesson 6

Key Function
    o Open new line below.
    O Open new line above.
    e Go to the end of the word.
    2e Go to the end of two words.
    R Enter replace mode.
    yw Yank Word.
    vwy Visual select word then yank.
    y$ Yank to the end of the Current Line.
    :set ignorecase Change the search settings to ignore case.
    :set noignorecase Change the search settings to use case.

Recording Macro Function

Key Function
    q To start recording macro.
    Any key between (a - z) This will assign the key on which the macro is recorded.
    q Press q again to stop recording macro.
    @ + the key between (a-z) the macro was recorded on This will run the macro.
    @ + @ After running the macro you can use this to repeat the macro.

Some important settings and shortcuts.

Key Function
    :set number Shows the line number
    :set relativenumber Shows the number of lines above and below makes it easy and quick to navigate.
    yy To copy whole line.
    cc To change whole line.
    * and # To find other instances of the same word or character.
    zz To center the view page.
    . To repeat the recent action.
    t To transfer cursor before the stated character. For example t* will transfer the cursor to a place just before * in the code.
    f Will find and transfer the cursor to the stated character. For exapmle f* will put the cursor on * looking forward in the code.
    T Will perform similar function as t but in reversed order.
    F Will perform similar function as f but in reversed order.

Understanding Registry for copy and pasting stuffs.

Key Function
    :register Shows the register where the history of yanking and cutting is stored.
    "(a-z)y This will help to create a custom register to the assigned key between or the selected text can be yanked to any key from a-z.
    "(a-z)p This will paste custom register created.

Use of i or in

Key Function
    ci( or di( or ci{ or di[ ci( will change the text within (). di( will delete the text within (). This will be the same with any of the stated brackets.
    yiw This will copy the word between which the cursor is.
    diw This will delete the word between which the cursor is.