Vim Cheatsheet
Press ESC to return to Normal mode
Movement
h j k l
Move left, down, up, right
w b e
Move to beginning/end of word
W B E
Move by WORDS (ignore punctuation)
0 ^ $
Move to start, first non-blank, end of line
gg G
Move to top/bottom of file
{ }
Move to previous/next paragraph
( )
Move to previous/next sentence
Ctrl + f/b
Page forward/backward
H M L
Move to top/middle/bottom of screen
Modes
i I
Insert mode / Insert at beginning of line
a A
Append after cursor / Append at end of line
o O
Open new line below/above
s S
Substitute character / Substitute line
v V
Visual mode / Line visual mode
Ctrl + v
Visual block mode
ESC
Return to Normal mode
Editing
x X
Delete character under/before cursor
dd
Delete entire line
dw d$ d0
Delete word, to end of line, to start of line
cc
Change entire line
cw c$ c0
Change word, to end of line, to start of line
yy
Copy (yank) line
yw y$ y0
Copy word, to end of line, to start of line
p P
Paste after/before cursor
u Ctrl + r
Undo / Redo
. (dot)
Repeat last command
Search & Replace
/pattern
Search forward
?pattern
Search backward
n N
Next/previous search result
* #
Search word under cursor forward/backward
:%s/old/new/g
Replace all in file
:%s/old/new/gc
Replace with confirmation
:noh
Clear search highlighting
File Operations
:w
Save file
:w filename
Save as filename
:q
Quit
:wq
Save and quit
:q!
Quit without saving
:e filename
Open file
:e!
Revert to last saved version
:ls
List buffers
:b n
Switch to buffer n
Windows & Tabs
:sp
Split window horizontally
:vsp
Split window vertically
Ctrl + w w
Switch between windows
Ctrl + w h/j/k/l
Navigate windows in specific direction
Ctrl + w q
Close current window
:tabnew
Open new tab
gt gT
Next/previous tab
:tabclose
Close current tab
Text Objects
diw ciw yiw
Delete/Change/Yank inner word
das cas yas
Delete/Change/Yank a sentence
dip cip yip
Delete/Change/Yank inner paragraph
da" ca" ya"
Delete/Change/Yank around quotes
da( ca( ya(
Delete/Change/Yank around parentheses
Marks & Jumps
mx
Set mark x (a-z for local, A-Z for global)
`x
Jump to mark x (at exact position)
'x
Jump to mark x (at beginning of line)
''
Jump to previous position
:marks
List all marks
Registers
"ay
Yank to register a
"ap
Paste from register a
"+y
Yank to system clipboard
"+p
Paste from system clipboard
:reg
Show all registers
Essential Commands
>> <<
Indent/unindent line
=G
Auto-indent entire file
:set number
Show line numbers
:set nonumber
Hide line numbers
:set relativenumber
Relative line numbers (Vim 7.3+)
:set ignorecase
Case insensitive search
:set smartcase
Smart case search
:set wrap
Wrap long lines
:set nowrap
Don't wrap lines
Basic .vimrc Configuration
Place this in ~/.vimrc for a clean, basic Vim setup
set number
set relativenumber
set tabstop=4
set shiftwidth=4
set expandtab
set smartindent
set cindent
set nowrap
set mouse=a
set cursorline
set background=dark
set ignorecase
set smartcase
set hlsearch
set incsearch
set splitright
set splitbelow
set backupdir=~/.vim/backup
set directory=~/.vim/tmp
set undodir=~/.vim/undo
set undofile
let mapleader = "\\"
noremap <C-s> :w<CR>
inoremap <C-s> <Esc>:w<CR>a
inoremap jj <Esc>
noremap <Leader>/ :nohlsearch<CR>
noremap j gj
noremap k gk
vnoremap < <gv
vnoremap > >gv
if !isdirectory(expand('~/.vim/backup'))
call mkdir(expand('~/.vim/backup'), 'p')
endif
if !isdirectory(expand('~/.vim/tmp'))
call mkdir(expand('~/.vim/tmp'), 'p')
endif
if !isdirectory(expand('~/.vim/undo'))
call mkdir(expand('~/.vim/undo'), 'p')
endif
Plugin Management (vim-plug)
Install vim-plug and add to your .vimrc for plugin management
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-surround'
Plug 'scrooloose/nerdtree'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'morhetz/gruvbox'
Plug 'vim-airline/vim-airline'
call plug#end()