Skip to content

Instantly share code, notes, and snippets.

@moelzanaty3
Created December 23, 2024 00:02
Show Gist options
  • Save moelzanaty3/3de04f27e4d06c1733f4bf32c1ae2805 to your computer and use it in GitHub Desktop.
Save moelzanaty3/3de04f27e4d06c1733f4bf32c1ae2805 to your computer and use it in GitHub Desktop.

Most Used Vim Commands

Navigation Essentials

  • h, j, k, l - left, down, up, right
  • H, M, L - move to top, middle, bottom of screen
  • w - jump to start of next word
  • b - jump to start of previous word
  • 0 - jump to start of line
  • ^ - jump to first non-blank character of line
  • $ - jump to end of line
  • g_ - jump to last non-blank character of line
  • gg - go to top of file
  • 5gg - go to line 5
  • G - go to bottom of file
  • 4j - move down 4 lines / 4k - move up 4 lines
  • Ctrl+b - page up / Ctrl+f - page down
  • Ctrl+d - move half page down / Ctrl+u - move half page up

Insert Mode

  • i - insert before cursor / a - insert after cursor
  • o - insert new line below / O - insert new line above
  • A - insert at end of line / I - insert at start of line
  • Esc - exit insert mode

Editing

  • u - undo
  • Ctrl+r - redo
  • dd - delete line
  • s - delete character and enter insert mode
  • 5dd - delete 5 lines
  • yy - copy line
  • p - paste after cursor
  • P - paste before cursor
  • x - delete character
  • r - replace character
  • cw - change word
  • cc - change entire line
  • ci" - change text inside quotes
  • ci' - change text inside single quotes
  • ci( - change text inside parentheses
  • ci{ - change text inside curly braces
  • ci< - change text inside tags
  • . - repeat last command
  • J - join current line with next line

Visual Mode

  • v - start visual mode
  • V - start line-wise visual mode
  • Ctrl+v - start block-wise visual mode
  • aw - mark a word
  • a( - a block with ()
  • a{ - a block with {}
  • a< - a block with <> tags
  • i( - inner block with ()
  • i{ - inner block with {}
  • i< - inner block with <> tags
  • y - copy selected text
  • d - cut selected text
  • p - paste selected text
  • yaw - copy a word
  • > - indent selected text
  • < - unindent selected text
  • ~ - toggle case of selected text
  • u - change marked text to lowercase
  • U - change marked text to uppercase

Search

  • / - search forward
  • ? - search backward
  • n - next search result
  • N - previous search result
  • :%s/old/new/g - replace all occurrences
  • :noh - remove search highlighting

File Operations

  • :w - save file
  • :q - quit
  • :wq or :x - save and quit
  • :q! - quit without saving

Multiple Files

  • :e filename - edit a file
  • :sp filename - open file in horizontal split
  • :vsp filename - open file in vertical split
  • Ctrl+w h/j/k/l - navigate between splits

Other Useful Commands

  • zz - center cursor on screen
  • >> - indent line
  • << - unindent line
  • ci" - change text inside quotes
  • % - jump to matching bracket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment