Vim Cheatsheet Working With Files vim <filename> :w :q :wq :q! ZZ :w <filename> Editing Open a file in Vim Save a file Quit a file Save and quit Quit without saving Save (if modified) and exit Save a copy as filename Vim Modes Esc i v : Normal mode. Default starting mode. Insert mode. Esc to normal mode. Visual mode. Esc to normal mode. Command-line mode. Esc to normal mode. Move around (or h,j,k,l---left, down, up, right) End of line Beginning of line (this is a ‘zero’, not an ‘o’) Half-page up Half-page down Backwards a word Forward a word Bottom of file Top of file(or 1G) Display line numbering Hide line numbering Go to line 5 Vimdiff vimdiff <file1> <file2> ]c [c dp do :diffupdate Ctrl + ww Insert mode. Esc to normal mode. Insert new line below Insert new line above Insert at beginning of line Insert (append) at end of line Delete character Delete line Delete two lines Delete 5 characters Delete from cursor to end of file Delete from cursor to end of line Delete from cursor to beginning of file Yank (copy) a line Visual Mode Navigating Arrow keys $ 0 Ctrl + u Ctrl + d b w G gg :set number :set nonumber :5 i o O I A x dd 2dd 5x dG d$ dgg yy Compare file1 (left) and file2 (right) Go to next diff Go to previous diff Diff put Diff get Rescan files for changes Switch between split windows v Arrow keys y c d p Esc Enter Visual mode Highlight text in Visual mode Yank (copy) selection Change (cut) selection Delete selection Paste selection. Esc to enter normal mode to paste. Enter normal mode Build Efficiency u Ctrl + r /searchterm n N :%s/replaceme/withme/g :%s/replaceme/withme/gc :set paste :set nopaste ?searchterm . Undo (from normal mode) Redo (from normal mode) Search for searchterm. Add \c for case insensitive. Next instance of searchterm Previous instance of searchterm Replace "replaceme" with "withme" in the entire file Replace "replaceme" with "withme" and prompt Disable auto-indent upon paste Re-enable auto-indent upon paste Search backwards in file for searchterm Repeat last change