Vim

Basics

move

		k
	h 		l
		j

move between words

         words! _a_re words
    w    words! are _w_ords
    e    words! ar_e_ words
    b    words_!_ are words
    B    _w_ords! are words
multipliers

number + [h, j, k, l , w, e, b]

    5h    wor_d_s! are words
    2e    words! are word_s_

move to matching parenthesis

         words! _{_are} words
    %    words! {are_}_ words

move to start/end of line

    0    _w_ords! are words
    $    words! are word_s_

edit text

i > INSERT mode
ESC > NORMAL mode

         words! _a_re words
    
    # cut, cut line, copy, paste,
    x    words! re words
    dd   # line is cut
    
    p    words! are words # or paste line below
    P    paste line above
    
    # insert, append, append eol
    i    words! a_re words
    a    words! ar_e words    
    A    words! are words_    

    o       open new line below then insert mode
    O       open new line above then insert mode
    

replace

    :s/old/new         replace 1 occurence in current line
    :s/old/new/g       replace all occurrences in current line
    :%s/old/new/gc     replace all occurrences in file, confirm each
    :8,18s/old/new/g   replace all ocurrences between lines 8 to 18

    R           Enter replace mode
    
multipliers

Insert text n-times
number + i + text + ESC

    3iwords_   words_words_words_

Works with movements, edit commands, etc...

find (search)

f + character

    fp   words! a_r_e words
    2fp  words! are wo_r_ds

words

    /word      find next word
    ?word      find prev word
    CTRL-O      find prev word
    n          next
    N          previous
    shift + *  next occurrence <word under cursor>
    shift + #  prev occurrence <word under cursor>

matching bracket

    %   find match bracket

ignore case :set ic
ignore case off :set noic
highlight :set hls
inc partial :set is

Go to

    gg   first line
    G    last line
    gD   declaration of variable
    gD   global declaration of variable
    g*   next rep of word under cursor (fwd search)
    g#   prev rep of word under cursor (bwd search)   
    gf   to file path under cursor
    8G   Go to line 8
    8gg  Go to line 8
    :8   Go to line 8 

Delete, undo, redo

    x         cut (character)
    dd        delete line
    dw        delete word
    d$        delete to end of line
    d0        delete to start of line
    u         undo last change
    U         undo all changes in line

Re do last CTRL-R

Replace and change

   r + char     replace char under cursor
   R            replace mode
   cw           change word: remove from cursor and insert
   ce           change word: remove from cursor and insert
   ciw          change inner word: remove word and insert

visual mode

    v    switch to visual mode
    y    yank: copy and Normal mode
    p    paster after cursor
    P    paste before cursor

    # y as operator
    y2w  yank 2 words

Back to prev buffer ctrl + o, forward is ctrl + i

Save selected text to new file :w new_file after selected text
Retrieve(merge) existing file into current file :r new_file

executing

    :!ls    execute external shell command and back to vim  

exit

NORMAL model

    :q!     force quit
    :wq     write & quit
    :w new  save to file named 'new'

Customization

Plugins

Training

Cheat sheets

Basics

Check vimtutor

Videos

Challenges

Games

Other