VIM
MODES#
i # Insert mode (before cursor) I # Insert at line beginning a # Append (after cursor) A # Append at line end o # Open new line below O # Open new line above v # Visual mode (character) V # Visual mode (line) Ctrl+v # Visual block mode R # Replace mode Esc # Normal mode
NAVIGATION#
h j k l # Left, down, up, right
w # Next word start
W # Next WORD start
e # Next word end
E # Next WORD end
b # Previous word start
B # Previous WORD start
0 # Line beginning
^ # First non-blank
$ # Line end
gg # File beginning
G # File end
5G # Go to line 5
:5 # Go to line 5
% # Matching bracket
{ # Previous paragraph
} # Next paragraph
Ctrl+d # Half page down
Ctrl+u # Half page up
Ctrl+f # Full page down
Ctrl+b # Full page up
H # Screen top
M # Screen middle
L # Screen bottom
zz # Center screen on cursor
zt # Cursor at screen top
zb # Cursor at screen bottom
EDITING#
x # Delete character X # Delete character before r # Replace character s # Substitute character S # Substitute line c # Change (with motion) cw # Change word cc # Change line C # Change to line end d # Delete (with motion) dw # Delete word dd # Delete line D # Delete to line end y # Yank (copy) yw # Yank word yy # Yank line Y # Yank line p # Paste after P # Paste before u # Undo Ctrl+r # Redo . # Repeat last command J # Join lines ~ # Toggle case
TEXT OBJECTS#
iw # Inner word aw # A word (with space) is # Inner sentence as # A sentence ip # Inner paragraph ap # A paragraph i" # Inner quotes a" # A quotes (with quotes) i' # Inner single quotes i) # Inner parentheses i] # Inner brackets i} # Inner braces it # Inner tag at # A tag # Examples diw # Delete inner word ci" # Change inside quotes da) # Delete around parentheses yi} # Yank inside braces vat # Visual select tag
SEARCH & REPLACE#
/pattern # Search forward ?pattern # Search backward n # Next match N # Previous match * # Search word under cursor # # Search word backward :noh # Clear highlight # Replace :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 with confirm :5,10s/old/new/g # Replace in range :'<,'>s/old/new/g # Replace in selection # Regex flags g # Global i # Case insensitive c # Confirm n # Count only
FILES & BUFFERS#
:e filename # Open file :w # Save :w filename # Save as :wq # Save and quit :x # Save and quit ZZ # Save and quit :q # Quit :q! # Force quit :qa # Quit all :wqa # Save and quit all :bn # Next buffer :bp # Previous buffer :bd # Delete buffer :ls # List buffers :b1 # Go to buffer 1 :e! # Reload file
WINDOWS & TABS#
:sp # Horizontal split :vs # Vertical split Ctrl+w s # Horizontal split Ctrl+w v # Vertical split Ctrl+w w # Switch window Ctrl+w h/j/k/l # Navigate windows Ctrl+w H/J/K/L # Move window Ctrl+w = # Equal size Ctrl+w _ # Max height Ctrl+w | # Max width Ctrl+w c # Close window Ctrl+w o # Only this window :tabnew # New tab :tabn # Next tab :tabp # Previous tab gt # Next tab gT # Previous tab :tabclose # Close tab
VISUAL MODE#
v # Character visual V # Line visual Ctrl+v # Block visual o # Toggle cursor position gv # Reselect > # Indent < # Unindent = # Auto indent U # Uppercase u # Lowercase ~ # Toggle case
MACROS#
qa # Start recording to 'a' q # Stop recording @a # Play macro 'a' @@ # Replay last macro 5@a # Play 5 times
REGISTERS#
"ayy # Yank to register 'a' "ap # Paste from register 'a' :reg # List registers "+y # Yank to clipboard "+p # Paste from clipboard "0p # Paste last yank
MARKS#
ma # Set mark 'a' 'a # Go to mark 'a' (line) `a # Go to mark 'a' (exact) :marks # List marks '' # Previous position '. # Last edit
FOLDING#
zf # Create fold zo # Open fold zc # Close fold za # Toggle fold zR # Open all zM # Close all zd # Delete fold
MISC#
:!command # Run shell command :r !command # Insert command output :r filename # Insert file content Ctrl+a # Increment number Ctrl+x # Decrement number ga # Show character code :set nu # Show line numbers :set nonu # Hide line numbers :set paste # Paste mode :set nopaste # Normal mode :syntax on # Syntax highlight :set hlsearch # Highlight search :set ignorecase # Case insensitive :set smartcase # Smart case search
VIMRC ESSENTIALS#
set number " Line numbers set relativenumber " Relative numbers set tabstop=4 " Tab width set shiftwidth=4 " Indent width set expandtab " Spaces instead of tabs set autoindent " Auto indent set smartindent " Smart indent set hlsearch " Highlight search set incsearch " Incremental search set ignorecase " Case insensitive set smartcase " Smart case set wildmenu " Command completion set mouse=a " Enable mouse syntax on " Syntax highlighting filetype plugin indent on
VIM CHEATSHEET
==============
Source: https://cheatsheet.johlem.net
MODES
-----
i # Insert mode (before cursor)
I # Insert at line beginning
a # Append (after cursor)
A # Append at line end
o # Open new line below
O # Open new line above
v # Visual mode (character)
V # Visual mode (line)
Ctrl+v # Visual block mode
R # Replace mode
Esc # Normal mode
NAVIGATION
----------
h j k l # Left, down, up, right
w # Next word start
W # Next WORD start
e # Next word end
E # Next WORD end
b # Previous word start
B # Previous WORD start
0 # Line beginning
^ # First non-blank
$ # Line end
gg # File beginning
G # File end
5G # Go to line 5
:5 # Go to line 5
% # Matching bracket
{ # Previous paragraph
} # Next paragraph
Ctrl+d # Half page down
Ctrl+u # Half page up
Ctrl+f # Full page down
Ctrl+b # Full page up
H # Screen top
M # Screen middle
L # Screen bottom
zz # Center screen on cursor
zt # Cursor at screen top
zb # Cursor at screen bottom
EDITING
-------
x # Delete character
X # Delete character before
r # Replace character
s # Substitute character
S # Substitute line
c # Change (with motion)
cw # Change word
cc # Change line
C # Change to line end
d # Delete (with motion)
dw # Delete word
dd # Delete line
D # Delete to line end
y # Yank (copy)
yw # Yank word
yy # Yank line
Y # Yank line
p # Paste after
P # Paste before
u # Undo
Ctrl+r # Redo
. # Repeat last command
J # Join lines
~ # Toggle case
TEXT OBJECTS
------------
iw # Inner word
aw # A word (with space)
is # Inner sentence
as # A sentence
ip # Inner paragraph
ap # A paragraph
i" # Inner quotes
a" # A quotes (with quotes)
i' # Inner single quotes
i) # Inner parentheses
i] # Inner brackets
i} # Inner braces
it # Inner tag
at # A tag
# Examples
diw # Delete inner word
ci" # Change inside quotes
da) # Delete around parentheses
yi} # Yank inside braces
vat # Visual select tag
SEARCH & REPLACE
----------------
/pattern # Search forward
?pattern # Search backward
n # Next match
N # Previous match
* # Search word under cursor
# # Search word backward
:noh # Clear highlight
# Replace
: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 with confirm
:5,10s/old/new/g # Replace in range
:'<,'>s/old/new/g # Replace in selection
# Regex flags
g # Global
i # Case insensitive
c # Confirm
n # Count only
FILES & BUFFERS
---------------
:e filename # Open file
:w # Save
:w filename # Save as
:wq # Save and quit
:x # Save and quit
ZZ # Save and quit
:q # Quit
:q! # Force quit
:qa # Quit all
:wqa # Save and quit all
:bn # Next buffer
:bp # Previous buffer
:bd # Delete buffer
:ls # List buffers
:b1 # Go to buffer 1
:e! # Reload file
WINDOWS & TABS
--------------
:sp # Horizontal split
:vs # Vertical split
Ctrl+w s # Horizontal split
Ctrl+w v # Vertical split
Ctrl+w w # Switch window
Ctrl+w h/j/k/l # Navigate windows
Ctrl+w H/J/K/L # Move window
Ctrl+w = # Equal size
Ctrl+w _ # Max height
Ctrl+w | # Max width
Ctrl+w c # Close window
Ctrl+w o # Only this window
:tabnew # New tab
:tabn # Next tab
:tabp # Previous tab
gt # Next tab
gT # Previous tab
:tabclose # Close tab
VISUAL MODE
-----------
v # Character visual
V # Line visual
Ctrl+v # Block visual
o # Toggle cursor position
gv # Reselect
> # Indent
< # Unindent
= # Auto indent
U # Uppercase
u # Lowercase
~ # Toggle case
MACROS
------
qa # Start recording to 'a'
q # Stop recording
@a # Play macro 'a'
@@ # Replay last macro
5@a # Play 5 times
REGISTERS
---------
"ayy # Yank to register 'a'
"ap # Paste from register 'a'
:reg # List registers
"+y # Yank to clipboard
"+p # Paste from clipboard
"0p # Paste last yank
MARKS
-----
ma # Set mark 'a'
'a # Go to mark 'a' (line)
`a # Go to mark 'a' (exact)
:marks # List marks
'' # Previous position
'. # Last edit
FOLDING
-------
zf # Create fold
zo # Open fold
zc # Close fold
za # Toggle fold
zR # Open all
zM # Close all
zd # Delete fold
MISC
----
:!command # Run shell command
:r !command # Insert command output
:r filename # Insert file content
Ctrl+a # Increment number
Ctrl+x # Decrement number
ga # Show character code
:set nu # Show line numbers
:set nonu # Hide line numbers
:set paste # Paste mode
:set nopaste # Normal mode
:syntax on # Syntax highlight
:set hlsearch # Highlight search
:set ignorecase # Case insensitive
:set smartcase # Smart case search
VIMRC ESSENTIALS
----------------
set number " Line numbers
set relativenumber " Relative numbers
set tabstop=4 " Tab width
set shiftwidth=4 " Indent width
set expandtab " Spaces instead of tabs
set autoindent " Auto indent
set smartindent " Smart indent
set hlsearch " Highlight search
set incsearch " Incremental search
set ignorecase " Case insensitive
set smartcase " Smart case
set wildmenu " Command completion
set mouse=a " Enable mouse
syntax on " Syntax highlighting
filetype plugin indent on
Defensive reference on CyberRamen. Offensive / red-team sheets live on OffensiveRamen.com.