- Essential Editing
- Navigation
- Text Objects
- Visual Mode
- Search & Replace
- Window Management
- Advanced Operations
- Useful Commands
- Help & Discovery
- Special Operations
- Multilines
- Additional vim motions
x
: Delete character under cursor
- example:
x
→ delete 'a'
dw
: Delete word
- example:
dw
→ delete 'word'
dd
: Delete line
- example:
3dd
→ delete 3 lines
D
: Delete to end of line
- example:
D
→ delete rest of line
u
: Undo
- example:
u
→ undo last change
Ctrl+r
: Redo
- example:
Ctrl+r
→ redo
.
: Repeat last command
- example: After
dw
,.
→ delete next word
h
: Move left
- mnemonic: Left
j
: Move down
- mnemonic: Down
k
: Move up
- mnemonic: Up
l
: Move right
- mnemonic: Right
w
: Next word start
- mnemonic: word
b
: Previous word start
- mnemonic: back
e
: Next word end
- mnemonic: end
0
: Start of line
- mnemonic: Zero position
^
: First non-blank char
- mnemonic: (none)
$
: End of line
- mnemonic: (none)
gg
: Top of file
- mnemonic: (none)
G
: Bottom of file
- mnemonic: (none)
H
: Top of screen
- mnemonic: High
M
: Middle of screen
- mnemonic: Middle
L
: Bottom of screen
- mnemonic: Low
Ctrl+u
: Scroll up half page
- mnemonic: (none)
Ctrl+d
: Scroll down half page
- mnemonic: (none)
Ctrl+o
: Jump back to previous location
- mnemonic: (none)
Ctrl+i
: Jump forward to next location
- mnemonic: (none)
[{
: Previous block bracket
- mnemonic: (none)
]}
: Next block bracket
- mnemonic: (none)
[(
: Previous block curly
- mnemonic: (none)
])
: Next block curly
- mnemonic: (none)
ci"
: Change inside quotes
- mnemonic: change inside "quotes"
- example:
ci"
→ edit "text" between quotes
ci'
: Change inside single quotes
- mnemonic: change inside 'quotes'
- example:
ci'
→ edit 'text' between single quotes
ci(
: Change inside parentheses
- mnemonic: change inside (parens)
- example:
ci(
→ edit (text) inside parentheses
ci[
: Change inside brackets
- mnemonic: change inside [brackets]
- example:
ci[
→ edit [text] inside brackets
ci{
: Change inside braces
- mnemonic: change inside {braces}
- example:
ci{
→ edit {text} inside curly braces
cit
: Change inside HTML tag
- mnemonic: change inside
- example:
cit
→ edit<p>text</p>
within tags
ciw
: Change inside word
- mnemonic: change inner word
- example:
ciw
→ edit 'word' under cursor
yiw
: Yank inner word
- mnemonic: yank inner word
- example:
yiw
→ copy 'word' to register
diw
: Delete inner word
- mnemonic: delete inner word
- example:
diw
→ remove 'word' under cursor
vi{
: Visual/select inside braces
- mnemonic: visual inside {braces}
- example:
vi{
→ visual/select {text} inside curly braces
da"
: Delete around quotes
- mnemonic: delete around "quotes"
- example:
da"
→ delete "text" including quotes
dat
: Delete around HTML tag
- mnemonic: delete around
- example:
dat
→ delete<p>text</p>
entirely
v
: Enter character-wise visual mode
- mnemonic: visual
- example: Select characters by moving cursor
V
: Enter line-wise visual mode
- mnemonic: Visual-line
- example: Select entire lines by moving up/down
Ctrl+v
: Enter block visual mode
- mnemonic: Visual-block (Ctrl+v looks like block selection)
- example: Select vertical columns of text
>
: Indent selection
- mnemonic: Right angle = increase indent
- example:
>j
indents current and next line
<
: Unindent selection
- mnemonic: Left angle = decrease indent
- example:
<k
unindents current and previous line
y
: Yank (copy) selection
- mnemonic: yank
- example:
y
thenp
to paste selection
d
: Delete selection
- mnemonic: delete
- example:
d
removes highlighted text
~
: Toggle case of selection
- mnemonic: ~ looks like a tilde/wave for switching
- example:
~
changes "Text" to "tEXT"
gv
: Reselect last visual selection
- mnemonic: go visual
- example: After escape,
gv
re-highlights previous area
/pattern
: Search forward
- mnemonic: / leans forward → forward search
- example: /hello finds next "hello"
?pattern
: Search backward
- mnemonic: ? leans backward → backward search
- example: ?error finds previous "error"
n
: Next match
- mnemonic: next
- example: After /search, press n to find next
N
: Previous match
- mnemonic: Not-next (opposite of n)
- example: After /search, press N to go back
*
: Search word under cursor (forward)
- mnemonic: * is a wildcard → expand current word
- example: Over "text", * finds next "text"
#
: Search word under cursor (backward)
- mnemonic: # is shift+3 (opposite of *)
- example: Over "text", # finds previous "text"
:%s/old/new/g
: Replace all in file
- mnemonic: substitute globally
- example: :%s/cat/dog/g changes all "cat" to "dog"
:%s/old/new/gc
: Replace with confirmation
- mnemonic: confirm each change
- example: :%s/foo/bar/gc asks before each replace
:s/old/new/g
: Replace in current line
- mnemonic: No % → current line only
- example: :s/yes/no/g changes on current line
Ctrl+w c
: Close current window
- mnemonic: close
- example: Closes current pane (buffer stays loaded)
Ctrl+w o
: Close other windows
- mnemonic: only
- example: Keeps only current pane open
Ctrl+w =
: Equalize window sizes
- mnemonic: = (equals sign for balance)
- example: Makes all panes equal size
Ctrl+w _
: Maximize current window
- mnemonic: _ (underscore = expand height)
- example: Current pane takes full height
:sp
: Horizontal split
- mnemonic: split horizontally
- example: :sp file.txt opens file in pane below
:vsp
: Vertical split
- mnemonic: vertical split
- example: :vsp file.txt opens file in pane to the right
Ctrl+w s
: Split window horizontally
- mnemonic: split (same as :sp)
- example: Splits current buffer horizontally
Ctrl+w v
: Split window vertically
- mnemonic: vertical (same as :vsp)
- example: Splits current buffer vertically
:res +20
: Resize horizontal window
:vert res +80
: Resize vertical
Ctrl+w o
: Close all window except active window\
Ctrl+w r
: Rotate window
gt
: Go to next tab
gT
: Go to previous tab
2gt
: Go to tab number 2
Ctrl+w h
: Move to left window
- mnemonic: h (vim's left movement key)
- example: Move cursor to left pane
Ctrl+w j
: Move to window below
- mnemonic: j (vim's down movement key)
- example: Jump to lower pane
Ctrl+w k
: Move to window above
- mnemonic: k (vim's up movement key)
- example: Jump to upper pane
Ctrl+w l
: Move to right window
- mnemonic: l (vim's right movement key)
- example: Move cursor to right pane
:tabn
: Switch to next tab
mnemonic: Tab Next
:tabp
: Switch to previous tab
mnemonic: Tab Previous
:tabfirst
: Switch to first tab
mnemonic: -
:tablast
: Switch to last tab
mnemonic: -
2gt
: Switch to tab number 2
mnemonic: Go to Tab 2
q[a-z]
: Start recording macro
- mnemonic: queue recording in register [a-z]
- example:
qa
starts recording to register 'a'
q
: Stop recording macro
- mnemonic: quit recording
- example: Press
q
to finish macro recording
@[a-z]
: Execute macro
- mnemonic: **@**tack (run) from register [a-z]
- example:
@a
plays back macro from 'a'
@@
: Repeat last macro
- mnemonic: Double @ = repeat last action
- example: After
@a
,@@
runs 'a' again
Ctrl+a
: Increment number
- mnemonic: +a (think addition)
- example: On
42
, becomes43
Ctrl+x
: Decrement number
- mnemonic: -x (think subtraction)
- example: On
42
, becomes41
gq
: Format text
- mnemonic: good quote (for text wrapping)
- example:
gqip
reformats current paragraph
==
: Auto-indent line
- mnemonic: = (equals for alignment)
- example: Fixes indentation on current line
gg=G
: Auto-indent entire file
- mnemonic: gg (start) = (indent) G (end)
- example: Properly indents whole file
:w
- Save file
- mnemonic: write
- example: :w myfile.txt saves to myfile.txt
:q
- Quit
- mnemonic: quit
- example: :q closes current window
:wq
- Save and quit
- mnemonic: write + quit
- example: :wq saves changes and exits
:q!
- Force quit without saving
- mnemonic: ! means "force"
- example: :q! discards all changes
:e
file - Open file
- mnemonic: edit
- example: :e ~/.vimrc opens vim config
:e!
- Reload file (discard changes)
- mnemonic: ! means "discard current"
- example: :e! reverts to saved version
:saveas
- Save as new file
- mnemonic: literal meaning
- example: :saveas backup.txt creates copy
:set nu
- Show line numbers
- mnemonic: numbers
- example: :set nu displays line numbers
:set nonu
- Hide line numbers
- mnemonic: no numbers
- example: :set nonu hides numbering
:set paste
- Enable paste mode
- mnemonic: literal
- example: Before pasting external text
:set nopaste
- Disable paste mode
- mnemonic: nopaste
- example: After pasting to resume formatting
:help [topic]
- Open help
- mnemonic: Literal
- example:
:help w
- Show help for 'w' command:help :w
- Show help for :w command:help options
- Learn about configuration
:options
- Open interactive options window
- mnemonic: Literal
- example: Browse/change settings with GUI-like interface
:map
- Show all custom key mappings
- mnemonic: Literal
- example:
:map
- Shows normal mode mappings:vmap
- Shows visual mode mappings:imap
- Shows insert mode mappings
:verb map <key>
- Show key's definition and origin
- mnemonic: verbose mapping
- example:
:verb map <Leader>f
- Shows where f was defined:verb map <C-Space>
- Debug complex key combinations
:reg
- Show register contents
- mnemonic: registers
- example:
:reg
- Shows all registers:reg a
- Show only register 'a'"ap
- Paste from register 'a'
:marks
- Show all marks
- mnemonic: Literal
- example:
:marks
- List all marksa
- Jump to mark 'a'.
- Jump to last edit position
gd
: Go to definition
- mnemonic: go definition
- example: Hover over function →
gd
jumps to its definition
K
: Show documentation
- mnemonic: Know (like man pages)
- example: Cursor on function →
K
shows its docs
Ctrl+]
: Jump to tag definition
- mnemonic: ] looks like arrow pointing in
- example: Jump to function/variable declaration
Ctrl+t
: Jump back from tag
- mnemonic: tag back
- example: Return from definition jump
do
: Diff obtain (get changes)
- mnemonic: diff obtain
- example: In diff view, pull changes from other file
dp
: Diff put (send changes)
- mnemonic: diff put
- example: In diff view, push changes to other file
]c
: Next diff
- mnemonic: ] moves forward
- example: Jump to next changed block
[c
: Previous diff
- mnemonic: [ moves backward
- example: Jump to previous changed block
zc
: Close fold
- mnemonic: zip close
- example: Collapse current code block
zo
: Open fold
-
- mnemonic: zip open
-
- example: Expand current collapsed block
za
: Toggle fold
-
- mnemonic: zip alternate
-
- example: Toggle current fold state
zR
: Open all folds
- mnemonic: Recursively open
- example: Expand all nested folds
zM
: Close all folds
- mnemonic: Maximally close
- example: Collapse entire file structure
o
: new line under cursor
O
: new line above cursor
5o
: 5 new line under cursor
5O
: 5 ne line above cursor
$F"
or va"<Esc>
or vi"<Esc>
: navigate last double quote
Pro Tip: Combine motions with commands for powerful editing:
d3w
→ Delete 3 words forwardc$
→ Change to end of lineyG
→ Yank to end of file>j
→ Indent current and next line