hjkl

    The Vim Cheatsheet

    A comprehensive guide to the most useful Vim commands. Because if you're going to use @iusevimbtw.com, you'd better know how to use it.

    Basic Commands

    Command reference for Vim users of all levels

    CommandDescription
    iEnter insert mode
    EscReturn to normal mode
    :wSave file
    :qQuit Vim
    :wqSave and quit
    :q!Quit without saving
    h, j, k, lMove cursor left, down, up, right

    Text Manipulation

    Command reference for Vim users of all levels

    CommandDescription
    uUndo
    Ctrl+rRedo
    ddDelete line
    yyCopy (yank) line
    pPaste after cursor
    PPaste before cursor
    dwDelete word
    cwChange word

    Search and Replace

    Command reference for Vim users of all levels

    CommandDescription
    /Search forward
    ?Search backward
    nNext search result
    NPrevious search result
    :%s/old/new/gReplace all occurrences of "old" with "new"
    :s/old/new/gReplace all occurrences of "old" with "new" on current line

    Advanced Commands

    Command reference for Vim users of all levels

    CommandDescription
    ggGo to beginning of file
    GGo to end of file
    ZZSave and quit
    ZQQuit without saving
    :e filenameOpen file
    :splitSplit window horizontally
    :vsplitSplit window vertically
    Ctrl+w wSwitch between windows

    Visual Mode

    Command reference for Vim users of all levels

    CommandDescription
    vEnter visual mode (character-wise)
    VEnter visual mode (line-wise)
    Ctrl+vEnter visual mode (block-wise)
    yYank (copy) selected text
    dDelete selected text
    cChange selected text
    >Indent selected text
    <Un-indent selected text

    Exit Vim: The Ultimate Challenge

    According to legend, some developers are still trying to figure out how to exit Vim. Here's the sacred knowledge:

    const exitVim = () => {

    // Press Escape to make sure you're in normal mode

    const saveChanges = true;

    if (saveChanges) {

    return ":wq"; // Write and quit

    } else {

    return ":q!"; // Force quit, discard changes

    }

    };

    // But remember, you can check in any time you like, but you can never leave