50%

Vim Cheat Sheet

A Vim Cheat sheet is a document that provides a summary or shortcuts of the commands available in the vim text editor. Vi IMproved often referred to as Vim, is a text editor for Unix-like systems. Vim is one of the most popular code editors.

Clipboard

  • x
    Delete character(Cut)
    c
    Copy character
    dd
    Delete line (Cut)
    yy
    Yank (Copy) Current line
    p
    Paste the clipboard after cursor
    P
    Paste Before Cursor
    "*p / "+p
    Paste from system clipboard
    "*y / "+y
    Paste to system clipboard

Exiting insert mode

  • Esc / <C-[>
    Exit insert mode
    [C-C]
    Abort current command

Exiting with an error

  • :cq
    Exiting with an error (aborting Git)
    :cquit
    Great for aborting Git commands.

Spell

  • :setspell spelllang=en_us
    Turn on US English spell checking
    ]s
    Move to next misspelled word after the cursor
    [s
    Move to previous misspelled word before the cursor
    z=
    Suggest spellings for the word under/after the cursor
    zg
    Add word to spell list
    zw
    Mark word as bad/mispelling
    zu / <C-x> (Insert Mode)
    Suggest words for bad word under cursor from spellfile
    $
    Jump to the end of line
    See :help spell

Marks

  • `^
    Last position of cursor in insert mode
    `.
    Last change in current buffer
    `"
    Last exited current buffer
    `0
    In last file edited
    ' '
    Back to line in current buffer where jumped from
    ` `
    Back to position in current buffer where jumped from
    `[
    To beginning of previously changed or yanked text
    `]
    To end of previously changed or yanked text
    `<
    To beginning of last visual selection
    `>
    To end of last visual selection
    :marks
    List all current marks
    :delm a
    Delete mark a
    :delm a-d
    Delete marks a, b, c, d
    :delm abc
    Delete marks a, b,
    ma
    Mark this cursor position as a
    `a
    Jump to the cursor position a
    `a
    Jump to the beginning of the line with position a
    'a
    Jump to the beginning of the line with position a
    d'a
    Delete from current line to line of mark a
    d`a
    Delete from current position to position of mark a
    c'a
    Change text from current line to line of a
    y`a
    Yank text from current position to position of a

Case

  • ~
    Toggle case (Case => cASE)
    gU
    Uppercase
    gu
    Lowercase
    gUU
    Uppercase current line
    guu
    Lowercase current line
    Do these in visualor normal mode.

Usage

  • These are performed in normal mode.
    d
    Operator
    w
    Motion

Jumping

  • <C-o>
    Go back to previous location
    <C-i>
    Go forward
    gf
    Go to file in cursor

Visual Mode

  • v
    Enter visual mode
    V
    Enter visual line mode
    <C-V>
    Enter visual block mode
    d | x
    Delete selection (Cut)
    s
    Replace selection
    y
    Yank selection (Copy)

Editing

  • a
    Append
    A
    Append from end of line
    i
    Insert
    o
    Next line
    O
    Previous line
    s
    Delete char and insert
    S
    Delete line and insert
    C
    Delete until end ofline and insert
    r
    Replace one character
    R
    Enter Replace mode
    u
    Undo changes
    d
    Delete one character
    <C-r>
    Redo changes

Know more about VIM

Text alignment

  • :center [width]
    :right [width]
    :left [width]
    See :help formatting

Command line

  • <C-r><C-w>
    Insert current word into the command line
    <C-r>"
    Paste from “ register
    <C-x><C-f>
    Auto-completion of path in insert mode

Misc

  • .
    Repeat last command
    ]p
    Paste under the current indentation level
    :set ff=unix
    Convert Windows line endings to Unix line endings

Windows

  • z{height}<Cr>
    Resize pane to {height} lines tall

Folds

  • zo / zO
    Open
    zc / zC
    Close
    za / zA
    Toggle
    zv
    Open folds for this line
    zM
    Close all
    zR
    Open all
    zm
    Fold more(foldlevel+= 1)
    zr
    Fold Less(foldlevel-= 1)
    zx
    Update folds
    Uppercase ones are recursive.(eg, zO is open recursively).

Examples

  • Combine operators with motions to use them.
    dd
    (repeat the letter) Delete current line
    dw
    Delete to next word
    db
    Delete to beginning of word
    2dd
    Delete 2 lines
    dip
    Delete a text object (inside paragraph)
    (in visual mode) d
    Delete selection
    See: :help motion.txt

Text objects

  • p
    Paragraph
    w
    Word
    s
    Sentence
    [ ( { <
    A [], (), or {} block
    ' " `
    A quoted string
    b
    A block [(
    a
    A link
    B
    A block in [{
    t
    A Html tag block

Examples

  • vip
    Select inner paragraph
    vipipipip
    Select more paragraph
    yip
    Yank inner paragraph
    yap
    Yank paragraph (including newline)
    dip
    Delete inner paragraph
    cip
    Change inner paragraph
    See Operators for other things you can do.

Usage

  • Text objects let you operate in or around text blocks.
    v
    Operator
    i
    [i]nside or [a]round
    p
    Text object;

Navigation

  • %
    Nearest/matching {[()]}
    [( [{ [<
    Previous ( or { or <
    ])
    Next ( or [
    [m
    Previous method start
    [M
    Previous method end

Operators list

  • d
    Delete
    y
    Yank (copy)
    c
    Change (delete then insert)
    >
    Indent right
    <
    Indent left
    =
    Autoindent
    g~
    Swap case
    gU
    Uppercase
    gu
    Lowercase
    !
    Filter through external program
    See :help operator

Vim CheatSheet Online


A Vim Cheat sheet is a reference guide that lists and explains the most commonly used Vim commands and features. It can be a helpful resource for new users who are learning Vim or experienced users who want to reference a specific command quickly. Some Vim cheat sheets also include tips and tricks for using Vim more efficiently.

What is Vim?

Vim is a text editor that is widely used in the programming community. It is known for its powerful editing capabilities and ability to use only a keyboard efficiently. Because Vim has many commands and features, it can be intimidating for new users to learn. Vim is an upgraded version of the vi editor, with additional features, including syntax highlighting, advanced search and replaces, folding, spell checking, and scripting.

Know more about Vim on Wikipedia

  • The online Vim Cheat Sheet works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.