Skip to content

Instantly share code, notes, and snippets.

@ehsan18t
Last active March 4, 2024 19:45
Show Gist options
  • Save ehsan18t/43d6b1bff474f0de8d164697b506f684 to your computer and use it in GitHub Desktop.
Save ehsan18t/43d6b1bff474f0de8d164697b506f684 to your computer and use it in GitHub Desktop.

Vim Cheatsheet for Beginners

These commands are tested in VSCode with Vim plugin.

ย 

๐Ÿ’  Mode

  • ESC / Ctrl + [ - Normal Mode
  • a - Insert Mode (After Current Char)
  • i - Insert Mode (Before Current Char)
  • v - Visual Mode / Selection Mode
  • R - Replace Mode
  • : - Command Mode

ย 

๐Ÿ’  Arrow

  • h - Left arrow
  • l - Right arrow
  • j - Down arrow
  • k - Up arrow

ย 

๐Ÿ’  Search

  • /pattern - Search forward
  • ?pattern - Search backward
  • n - Repeat search forward
  • N - Repeat search backward

ย 

๐Ÿ’  Jump

๐Ÿ”น Char (Inside Current Line)

  • fc - Go forward to character c
  • Fc - Go backward to character c
  • tc - Go forward before character c
  • Tc - Go backward before character c
  • ; - Go forward next
  • , - Go backward next

๐Ÿ”น Word

  • e - Last char before space
  • w - Next word (first char)
  • b - Previous word (first char)
  • ge - Previous Word (last char)
  • * - Next same word
  • # - Previous same word

๐Ÿ”น Current Line

  • 0 - Start of the line
  • ^ - Start of the line (after whitespace)
  • I - Start of the line and insert (after whitespace)
  • $ - End of the line
  • A - End of the line and insert

๐Ÿ”น Line

  • o - Next line and insert
  • O - Previous line and insert
  • gg - First line
  • G - Last line
  • :n - Goto n line
  • nG - Goto n line

๐Ÿ”น Block / Paragraph

  • { - Move up
  • } - Move down
  • % - Jump between braces (( ), { }, [ ])

๐Ÿ”น Window / Page

  • zz - Center this line
  • zt - Top this line
  • zb - Bottom this line
  • H - Top of screen
  • M - Middle of screen
  • L - Bottom of screen
  • Ctrl + u - Page up (Half page)
  • Ctrl + d - Page down (Half page)

๐Ÿ”น Tab

  • :tabclose - Close current tab
  • :tabfirst - First tab
  • :tablast - Last tab
  • :tabn - Next tab
  • tabp - Previous tab

ย 

๐Ÿ’  Select

  • ve - Select until next space
  • vw - Select until next word (Highlight word)
  • V - Select current line
  • v - Select current char (Highlight char)

ย 

๐Ÿ’  Copy

  • y - Copy selected (Only in visual mode)
  • yy - Copy current line
  • yw - Copy current word
  • yj - Copy current and previous line
  • yk - Copy current and next line

ย 

๐Ÿ’  Editing

๐Ÿ”น Paste

  • p - Paste next
  • P - Paste Previous

๐Ÿ”น Delete

  • x - Delete current char
  • s - Delete current char and insert
  • cw - Delete all char before space and insert (from cursor)
  • dw - Delete until next word
  • diw - Delete current word
  • X - Delete current word and insert (Custom bdwi)
  • dd - Delete current line
  • S - Delete current line and insert
  • D - Delete the rest of the line
  • C - Delete the rest of the line and insert

๐Ÿ”น Replace

  • r - Replace one character
  • R - Replace multiple character (Replace Mode)

๐Ÿ”น Undo/Redo

  • u - Undo changes
  • Ctrl + r - Redo

๐Ÿ’  Exit

  • :q - Close file
  • :q! - Close file, abandon changes
  • :qa - Close all files
  • :qa! - Close all files, abandon changes
  • :w - Save changes
  • :wq / :x - Save and close file
  • ZZ - Save and quit
  • ZQ - Quit without checking changes

๐Ÿ’  Notes & Combos

  • All keys mentioned above can be combined with one another.
    • Example: ct) can delete everything until ). That means it can be used for clear function parameter or something like that. Here c means cut and t) means forward until char ).
  • di{ - Delete everything inside {}
  • d2i{ - Delete everything inside {} and its surround {}.
  • ct} - Delete everything until } and insert.
  • d5$ - Delete next 5 lines after cursor.
  • 0d5$ - Delete next 5 lines including current.
  • cip - Delete paragraph and insert
  • di( - Delete everything inside ()
  • yi( - Copy everything inside ()
  • vi( - Highlight everything inside ()
  • diw - Delete current word

ย 

๐Ÿ’  Important VSCode Configurations for New Users

ย 

๐Ÿ”น Disable Vim ctrl+c ctrl+v ctrl+x commands

"vim.useCtrlKeys": true,
"vim.handleKeys": {
		"<C-c>": false,
		"<C-x>": false,
		"<C-v>": false
	}

ย 

๐Ÿ”น Disable Vim arrow controls

"vim.handleKeys": {
		"<": false,
		">": false
    }

ย 

๐Ÿ”น Enable jj to Normal Mode

"vim.insertModeKeyBindingsNonRecursive": [
        {
            "before": ["j", "j"],
            "after": ["<esc>"]
        }
    ]

ย 

๐Ÿ”น Enable X to Delete Current Word and Insert

"vim.normalModeKeyBindings": [
        {
            "before": ["X"],
            "after": ["b","d","w","i"]
        }
    ]

ย 

๐Ÿ”น Enable vim to use System Clipboard

"vim.useSystemClipboard": true

ย 

๐Ÿ”น Fix buggy undo redo and make it like vscode

"vim.normalModeKeyBindingsNonRecursive": [
        { 
            "before": ["u"], 
            "after": [],
            "commands": [
                {
                    "command": "undo", 
                    "args": []
                }
            ] 
        }, 
        { 
            "before": ["<C-r>"],
            "after": [],
            "commands": [
                {
                    "command": "redo", 
                    "args": []
                }
            ] 
        } 
    ]

ย 

๐Ÿ”น Enable move cursor to each wrapped line (if wrap line enable)

    {
        "before": ["j"],
        "after": ["g", "j"]
    },
    {
        "before": ["k"],
        "after": ["g", "k"]
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment