4

Some Useful vim Commands – My vim Cheatsheet


Posted by Artem Russakovskii on April 9th, 2008 in Linux, My Favorites, Programming

Updated: April 23rd, 2008

[WORK IN PROGRESS] Here is a list of commands that I use every day with vim, in no particular order. Out of a billion possible key combinations, I found these to be irreplaceable and simple enough to remember.

     

    *

    search for the word under cursor (to the end of the file)

    #

    search for the word under cursor (to the top of the file)

    ctrl-p,ctrl-n

    suggest (p)revious or (n)ext autocomplete from the list of existing keywords in the file or included files (!).

    :go NNN

    go to byte NNN

    .

    redo last command

    /SEARCH TERM

    search document for SEARCH TERM

    :%s/FOO/BAR/gci

    replace FOO with BAR (g)lobally, case (i)insensitively, and asking for (c)onfirmation

    n (N)

    next (previous) search result

    %

    find and jump to a matching brace or parenthesis

    u

    undo

    ctrl-r

    redo

    r CHAR

    replace character under curson with CHAR

    i

    start editing before current character

    I

    start editing in the beginning of current line

    a

    start editing after current character

    A

    start editing at the end of current line

    o

    start editing on the next line

    O

    start editing on the previous line

    :wq or ZZ

    write file and exit

    ctrl-v

    visual block select (rectangular)

    shift-v

    visual line select

    ctrl(or shift)-v y or d

    copy or delete selected text

    yy

    yank (copy) current line

    yNNN arrow up/down

    yank NNN lines above or below

    p

    paste the yanked buffer

    cw

    change word (delete word under cursor and go into edit mode)

    cNw

    change N words

    e!

    reload the file (revert)
● ● ●
Artem Russakovskii is a San Francisco programmer and blogger. Follow Artem on Twitter (@ArtemR) or subscribe to the RSS feed.

In the meantime, if you found this article useful, feel free to buy me a cup of coffee below.