Skip to content

Vim cheatsheet



  • :q quit
  • :q! quit without saving
  • :qa close all files and quit
  • :wq or :x save and close file


  • i insert
  • a append
  • A append at the end of line
  • o next line
  • O previous line
  • r replace one character
  • R replace mode
  • x delete character
  • u undo
  • <C-R> redo


  • yy copy line
  • p paste
  • P paste before
  • dd cut


  • :sort sort
  • :sort! sort in reverse order
  • :sort u sort and remove duplicates
  • :sort i ignore case

Search & replace

:s search and replace in current line

:%s search and replace in whole file

Note: ., *, \, [, ^, and $ are meta characters. +, ?, |, &, {, (, and ) must be escaped to use their special function.

Replace character with new line, use \r:



  • Open file in a new tab
:tabedit file.txt

or make the command shorter

:tabe file.txt
  • Open the file.txt in a new tab, or go to the tab with file.txt if it’s already open:
:tab drop file.txt
  • Open multiple files in tabs at startup
vim -p file1.txt file2.txt file3.txt

Moving between tabs

  • gt or :tabn - next tab
  • gT or :tabp - previous tab
  • Ngt go to tab number N - 1gt first tab, 2gt second tab etc.

Rearranging tabs

tabm N - move tab to position N (starting from 0)


Delete empty lines


Paste mode

set paste

Disable mouse

set mouse=""

Recover .swp file

Open vim, type: