VIM command cheat sheet

VIM is a powerful and popular text editor that runs on the command line. Using vim you will navigate around on screen with  keyboard instead of a mouse . It has a steep learning curve, but it can greatly improve your productivity once you master it. Here are some basic VIM commands to help you get started:

 Frequently used commands :
  • i  –  insert before the cursor

  • Esc  –  exit insert mode

  • : number  –  show line number

  • /pattern  –  search for pattern

  • n  –  repeat search in same direction

 

  • $  –  move cursor to end of line

  • GG  –  move cursor to bottom of page

  • gg  –  move cursor to top of page

  • yy  –  yank (copy) a line

 

  • p  –  put (paste) the clipboard after the cursor
  • :q  –  quit (fails if there are unsaved changes)

  • :wq   or  : x or  ZZ  –  write (save) and quit

  • :w  –   write (save) the file, but don’t exit

commands to move the cursor:
  • h   move cursor left
  • j  move cursor down
  • k  –   move cursor up
  •  – move cursor right
  • gj   move cursor down (multi-line text)
  • gk   move cursor up (multi-line text)
  • H  –  move to top of screen
  • M  –  move to middle of screen
  •   move to bottom of screen
  •   jump forwards to the start of a word
  • –  jump forwards to the start of a word (words can contain punctuation)
  • e  –  jump forwards to the end of a word
  •   jump forwards to the end of a word (words can contain punctuation)
  • –  jump backwards to the start of a word
  •   jump backwards to the start of a word (words can contain punctuation)
commands for Editing
  • r  replace a single character.
  • R –  replace more than one character, until ESC is pressed.
  • J  join line below to the current one with one space in between
  • gJ –  join line below to the current one without space in between
  • cc  –   change (replace) entire line
  • c$ or C   change (replace) to the end of the line
  • ciw  –  change (replace) entire word
  • cw or ce –    change (replace) to the end of the word
  • s  –   delete character and substitute text
  • –   delete line and substitute text (same as cc)
  • xp  –  transpose two letters (delete and paste)
  • –  undo
  • –  restore (undo) last changed line
  • Ctrl + r –   redo
  •    repeat last command
commands for saving and exiting
  • :w  –  write (save) the file, but don’t exit
  • :w !sudo tee %  –   write out the current file using sudo
  • :wq or : x or ZZ  – write (save) and quit
  • :q  –   quit (fails if there are unsaved changes)
  • :q! or ZQ  –   quit and throw away unsaved changes
  • :wqa  –   write (save) and quit on all tabs
command for search and replace
    • /pattern  –  search for pattern
    • ?pattern  –  search backward for pattern
    • n  –  repeat search in same direction
    • –  repeat search in opposite direction
commands for cut and paste
  • yy  –  yank (copy) a line
  • 2yy  –  yank (copy) 2 lines
  • yw  –  yank (copy) the characters of the word from the cursor position to the start of the next word
  • yiw  –  yank (copy) word under the cursor
  • y$ or  Y  – yank (copy) to end of line
  • –   put (paste) the clipboard after cursor
  • P  –  put (paste) before cursor
  • dd  –  delete (cut) a line
Visual commands
  • –   shift text right
  • <  –  shift text left
  • –   yank (copy) marked text
  • –   delete marked text
  • ~  –  switch case
  • u  –  change marked text to lowercase
  • –  change marked text to uppercase

Leave a Comment

Your email address will not be published. Required fields are marked *