Vim Commands

Essential Vim editor commands — modal editing, navigation, text manipulation, and more

Modes & Basics Core

EscReturn to Normal mode (from any other mode)
iEnter Insert mode (start typing before cursor)
IInsert at beginning of line
aAppend after cursor (enter Insert mode)
AAppend at end of line
oOpen new line below and enter Insert mode
OOpen new line above and enter Insert mode
vEnter Visual mode (character-wise selection)
VEnter Visual mode (line-wise selection)
Ctrl+vVisual block mode (column selection)
💡 Tip: Vim has multiple modes. Normal mode is for navigation and commands, Insert mode for typing text, Visual mode for selecting text.

Navigation Movement

h / j / k / lLeft / Down / Up / Right (arrow keys also work)
wJump to start of next word
bJump to start of previous word
eJump to end of current/next word
0 (zero)Move to beginning of line
$Move to end of line
^Move to first non-blank character of line
ggGo to first line of file
GGo to last line of file
:nGo to line number n (e.g., :42)
Ctrl+fScroll forward one page
Ctrl+bScroll backward one page
Ctrl+dScroll down half page
Ctrl+uScroll up half page
%Jump to matching parenthesis / bracket / brace

Editing & Text Manipulation Action

xDelete character under cursor
XDelete character before cursor
dDelete (cut) – combine with motion: dw (delete word), d$ (to end of line), dd (delete line)
DDelete from cursor to end of line (same as d$)
yYank (copy) – combine with motion: yw (copy word), yy (copy line), y$ (to end)
pPaste after cursor (or below current line)
PPaste before cursor (or above current line)
rReplace single character under cursor (no Insert mode)
REnter Replace mode (overwrite characters)
~Toggle case of character under cursor
uUndo last change
Ctrl+rRedo (undo an undo)
.Repeat last command
⏳ Pro tip: Most commands can be prefixed with a number, e.g., 5dd deletes 5 lines, 3w moves 3 words forward.

Search & Replace Find

/patternSearch forward for pattern
?patternSearch backward for pattern
nRepeat search in same direction
NRepeat search in opposite direction
*Search forward for word under cursor
#Search backward for word under cursor
:s/old/new/Replace first old with new on current line
:s/old/new/gReplace all old with new on current line
:%s/old/new/gReplace all occurrences in entire file
:%s/old/new/gcReplace with confirmation (asks for each)
:nohClear search highlighting

File & Buffer Management Save

:wSave (write) current file
:w filenameSave as filename
:qQuit (fails if unsaved changes)
:q!Quit without saving (force)
:wqSave and quit
:xSave and quit (only if changes)
:e filenameEdit (open) another file
:e!Reload file (discard changes)
:lsList open buffers (files)
:b nSwitch to buffer number n
:bnNext buffer
:bpPrevious buffer
:bdDelete buffer (close file)

Visual Mode & Selection Select

vStart Visual mode (character)
VStart Visual mode (line)
Ctrl+vStart Visual block mode (rectangular)
dDelete selected text (in Visual mode)
yYank (copy) selected text
cChange (delete and enter Insert mode) selected text
>Indent selected lines to the right
<Indent selected lines to the left
=Auto-indent selected lines

Windows & Tabs Layout

:splitSplit window horizontally (or :sp)
:vsplitSplit window vertically (or :vs)
Ctrl+w wSwitch to next window
Ctrl+w h/j/k/lMove to window left/down/up/right
Ctrl+w =Make all windows equal size
Ctrl+w + / -Increase / decrease window height
Ctrl+w > / <Increase / decrease window width
:tabnewOpen a new tab
gtGo to next tab
gTGo to previous tab
:tabcloseClose current tab

Advanced & Useful Power

:set numberShow line numbers (:set nonumber to hide)
:set relativenumberShow relative line numbers
:set hlsearchHighlight search matches
:set incsearchShow search matches as you type
:set ignorecaseCase-insensitive search
:set smartcaseCase-sensitive if pattern has uppercase
:set wrapWrap lines visually
:set nowrapDisable line wrapping
:nohlsearchTemporarily remove search highlights
:!commandExecute shell command (e.g., :!ls)
:r !commandInsert output of shell command into file
:helpOpen Vim help (:help topic for specific)
Ctrl+gShow file name and position info
gaShow ASCII/Unicode value of character
⚙️ Customization: Settings can be made permanent by adding them to your ~/.vimrc (or ~/.config/nvim/init.vim for Neovim).

Ex Commands (Command-line) :

:w !sudo tee %Save file with sudo (when you forgot to open as root)
:g/pattern/dDelete all lines matching pattern
:v/pattern/dDelete all lines not matching pattern
:g/pattern/t$Copy all matching lines to end of file
:g/pattern/m$Move all matching lines to end of file
:sortSort selected lines (or whole file if no selection)
:retabConvert tabs to spaces (or vice versa)
:source ~/.vimrcReload Vim configuration
Vim commands reference — inspired by the Linux Commands cheatsheet style.