Esc | Return to Normal mode |
i | Insert mode (before cursor) |
I | Insert at beginning of line |
a | Insert mode (after cursor) |
A | Insert at end of line |
o | Insert new line below |
O | Insert new line above |
v | Visual mode (character) |
V | Visual mode (line) |
Ctrl + v | Visual block mode |
R | Replace mode |
: | Command-line mode |
:w | Save file |
:w filename | Save as filename |
:q | Quit (fails if unsaved) |
:q! | Quit without saving |
:wq or :x or ZZ | Save and quit |
:e filename | Open file |
:e! | Reload file (discard changes) |
u | Undo |
U | Undo all changes on line |
Ctrl + r | Redo |
. | Repeat last command |
x | Delete character under cursor |
X | Delete character before cursor |
dd | Delete line |
dw | Delete word |
d$ or D | Delete to end of line |
d0 | Delete to beginning of line |
{number}dd | Delete {number} lines |
diw | Delete inner word |
daw | Delete a word (with spaces) |
di" | Delete inside quotes |
di( or dib | Delete inside parentheses |
di{ or diB | Delete inside braces |
cc or S | Change entire line |
cw | Change word |
c$ or C | Change to end of line |
ciw | Change inner word |
ci" | Change inside quotes |
ci( | Change inside parentheses |
s | Substitute character |
r{char} | Replace single character |
yy or Y | Yank (copy) line |
yw | Yank word |
y$ | Yank to end of line |
{number}yy | Yank {number} lines |
p | Paste after cursor |
P | Paste before cursor |
"+y | Yank to system clipboard |
"+p | Paste from system clipboard |
J | Join line below with space |
gJ | Join line below without space |
>> | Indent line |
<< | Unindent line |
== | Auto-indent line |
gg=G | Auto-indent entire file |
~ | Toggle case |
gUw | Uppercase word |
guw | Lowercase word |
v | Start character selection |
V | Start line selection |
Ctrl + v | Start block selection |
o | Move to other end of selection |
aw | Select a word |
ab | Select a block with () |
aB | Select a block with {} |
gv | Reselect last selection |
d | Delete selection |
y | Yank selection |
c | Change selection |
> | Indent selection |
< | Unindent selection |
= | Auto-indent selection |
U | Uppercase selection |
u | Lowercase selection |
I (block mode) | Insert at start of each line |
A (block mode) | Append at end of each line |
/pattern | Search forward |
?pattern | Search backward |
n | Next match |
N | Previous match |
* | Search word under cursor (forward) |
# | Search word under cursor (backward) |
:noh | Clear search highlighting |
:s/old/new/ | Replace first on line |
:s/old/new/g | Replace all on line |
:%s/old/new/g | Replace all in file |
:%s/old/new/gc | Replace all with confirmation |
:5,10s/old/new/g | Replace in line range (5-10) |
:'<,'>s/old/new/g | Replace in visual selection |
:ls or :buffers | List all buffers |
:b{number} | Go to buffer number |
:bn | Next buffer |
:bp | Previous buffer |
:bd | Delete (close) buffer |
:b filename | Go to buffer by name |
:split or :sp | Horizontal split |
:vsplit or :vs | Vertical split |
:sp filename | Open file in horizontal split |
:vs filename | Open file in vertical split |
Ctrl + w h/j/k/l | Move to left/down/up/right window |
Ctrl + w w | Move to next window |
Ctrl + w c | Close current window |
Ctrl + w o | Close all other windows |
Ctrl + w = | Equal size windows |
:tabnew | Open new tab |
:tabnew filename | Open file in new tab |
gt | Next tab |
gT | Previous tab |
{number}gt | Go to tab number |
:tabclose | Close current tab |
q{a-z} | Start recording macro |
q | Stop recording |
@{a-z} | Play macro |
@@ | Replay last macro |
{number}@{a-z} | Play macro {number} times |
:reg | Show all registers |
"{register} | Use register |
"0 | Last yank register |
"1-9 | Delete history registers |
"+ | System clipboard |
"_ | Black hole register (discard) |
:set number or :set nu | Show line numbers |
:set relativenumber | Show relative line numbers |
:set nonumber | Hide line numbers |
:set hlsearch | Highlight search results |
:set incsearch | Incremental search |
:set ignorecase | Case-insensitive search |
:set smartcase | Smart case search |
:set wrap / :set nowrap | Toggle line wrap |
:syntax on | Enable syntax highlighting |
:set tabstop=4 | Tab width = 4 spaces |
:set shiftwidth=4 | Indent width = 4 spaces |
:set expandtab | Use spaces instead of tabs |
:set autoindent | Auto indent |
:set smartindent | Smart indent |
:retab | Convert tabs to spaces |
~/.vimrc | User config file location |
:e $MYVIMRC | Edit vimrc |
:so $MYVIMRC | Reload vimrc |
let mapleader = "," | Set leader key |
nnoremap <leader>w :w<CR> | Normal mode mapping |
inoremap jk <Esc> | Insert mode mapping |
iw / aw | inner word / a word |
is / as | inner sentence / a sentence |
ip / ap | inner paragraph / a paragraph |
i" / a" | inner quotes / with quotes |
i' / a' | inner single quotes / with quotes |
i( / a( or ib / ab | inner parens / with parens |
i{ / a{ or iB / aB | inner braces / with braces |
it / at | inner tag / a tag (HTML) |
zf{motion} | Create fold |
za | Toggle fold |
zo | Open fold |
zc | Close fold |
zR | Open all folds |
zM | Close all folds |
:set foldmethod=indent | Fold by indent |
:!command | Run shell command |
:r !command | Insert command output |
:r filename | Insert file content |
:.!command | Filter line through command |
:%!command | Filter file through command |
:w !sudo tee % | Save file with sudo |
ci" | Change inside double quotes |
yiw | Yank inner word |
vip | Select inner paragraph |
dap | Delete a paragraph |
ggVG | Select entire file |
:g/pattern/d | Delete lines matching pattern |
:v/pattern/d | Delete lines not matching |
xp | Swap two characters |
ddp | Swap two lines |
ea | Insert at end of word |
:help keyword | Open help for keyword |
:help i_CTRL-N | Help for insert mode ctrl-n |
K | Open man page for word |
:version | Show Vim version info |