VIM Cheatsheet for everyone

Coding CorgiCoding Corgi
3 min read

Modes

  • Normal mode: The default mode for most commands.

  • Insert mode: Used for entering text.

  • Visual mode: Used for selecting text.

Basic Cursor Movements

  • Character-based movements:

    • h: Move left

    • j: Move down

    • k: Move up

    • l: Move right

  • Word-based movements:

    • w: Move to the start of the next word

    • e: Move to the end of the current word

    • b: Move to the start of the previous word

  • Line-based movements:

    • gg: Go to the first line

    • G: Go to the last line

    • 0: Go to the beginning of the line

    • ^: Go to the first non-blank character of the line

    • $: Go to the end of the line

Editing

  • Basic editing:

    • i: Enter insert mode before the cursor

    • a: Enter insert mode after the cursor

    • x: Delete the character under the cursor

    • dd: Delete the current line

    • dw: Delete from the cursor to the next word

    • de: Delete from the cursor to the end of the current word

    • diw: Delete the current word (regardless of cursor position)

  • Yanking (copying):

    • y: Yank (copy) the selected text

    • yy: Yank the current line

    • yw: Yank the current word

  • Pasting:

    • p: Paste the yanked text

    • P: Paste the yanked text before the cursor

  • Undo/Redo:

    • u: Undo the last edit

    • <CTRL-r>: Redo the last undo

  • Joining lines:

    • J: Join lines

Searching

  • Basic searching:

    • /pattern: Search forward for a pattern

    • ?pattern: Search backward for a pattern

    • n: Go to the next search result

    • N: Go to the previous search result

  • Word-based searching:

    • *: Search for the word under the cursor

    • #: Search backward for the word under the cursor

Visual Mode

  • Line mode:

    • v: Enter visual line mode
  • Block mode:

    • <CTRL-v>: Enter visual block mode
  • Editing in visual mode:

    • J: Join lines

    • x: Cut selected text

    • y: Yank selected text

    • r: Replace selected text with a character

    • I: Enter insert mode at the beginning of the selected block

    • A: Enter insert mode at the end of the selected block

Other Commands

  • Window navigation:

    • zz: Center the current line in the window
  • Character searching:

    • f{char}: Find the next occurrence of the character

    • F{char}: Find the previous occurrence of the character

    • t{char}: Move to the character before the next occurrence of the character

    • T{char}: Move to the character before the previous occurrence of the character

  • Brace/parenthesis matching:

    • %: Jump to the matching brace or parenthesis

    • [{: Jump to the opening brace or parenthesis

    • ]}: Jump to the closing brace or parenthesis

  • Text manipulation:

    • ci{symbol}: Change text within the specified symbols

    • cit: Change text within HTML tags

    • gcc: Comment or uncomment the current line

    • gc{motion}: Comment or uncomment the selected lines

    • >>: Indent the current line

    • <<: Unindent the current line

  • Number manipulation:

    • <CTRL-a>: Increment the number under the cursor

    • <CTRL-x>: Decrement the number under the cursor

  • Marks:

    • m{mark}: Set a mark

    • {mark}: Go to the specified mark

Reference:

If you are looking for a tutorial on VIM. Check out this VIM course from Zero To Mastery Academy by Jayson Lennon.

10
Subscribe to my newsletter

Read articles from Coding Corgi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Coding Corgi
Coding Corgi