VIM Cheat Sheet

Master VIM with this comprehensive reference guide. Find commands, shortcuts, and examples with this cheat sheet.

111 commands found
Filter by category:

h

Navigation

Move cursor left

Syntax:

h

Examples:

h Move one character to the left
5h Move five characters to the left

Notes:

Basic cursor movement command

j

Navigation

Move cursor down

Syntax:

j

Examples:

j Move one line down
10j Move ten lines down

Notes:

Basic cursor movement command

k

Navigation

Move cursor up

Syntax:

k

Examples:

k Move one line up
3k Move three lines up

Notes:

Basic cursor movement command

l

Navigation

Move cursor right

Syntax:

l

Examples:

l Move one character to the right
7l Move seven characters to the right

Notes:

Basic cursor movement command

w

Navigation

Move to beginning of next word

Syntax:

w

Examples:

w Move to next word
3w Move forward 3 words

Notes:

Stops at punctuation

W

Navigation

Move to beginning of next WORD (whitespace separated)

Syntax:

W

Examples:

W Move to next whitespace-separated word
2W Move forward 2 WORDs

Notes:

Ignores punctuation, only stops at whitespace

b

Navigation

Move to beginning of previous word

Syntax:

b

Examples:

b Move to previous word
2b Move back 2 words

Notes:

Stops at punctuation

B

Navigation

Move to beginning of previous WORD (whitespace separated)

Syntax:

B

Examples:

B Move to previous whitespace-separated word
3B Move back 3 WORDs

Notes:

Ignores punctuation

e

Navigation

Move to end of current word

Syntax:

e

Examples:

e Move to end of word
4e Move to end of 4th word ahead

Notes:

Useful for selecting to end of word

E

Navigation

Move to end of current WORD (whitespace separated)

Syntax:

E

Examples:

E Move to end of WORD
2E Move to end of 2nd WORD ahead

Notes:

Ignores punctuation

0

Navigation

Move to beginning of line

Syntax:

0

Examples:

0 Move to start of current line

Notes:

Goes to column 0

^

Navigation

Move to first non-blank character of line

Syntax:

^

Examples:

^ Move to first non-whitespace character

Notes:

Skips leading whitespace

$

Navigation

Move to end of line

Syntax:

$

Examples:

$ Move to end of current line
3$ Move to end of line 3 lines down

Notes:

Useful for line editing

gg

Navigation

Go to first line of file

Syntax:

gg

Examples:

gg Go to beginning of file
5gg Go to line 5

Notes:

Quick way to navigate to top

G

Navigation

Go to last line of file

Syntax:

G

Examples:

G Go to end of file
10G Go to line 10

Notes:

Quick way to navigate to bottom

Ctrl+u

Navigation

Scroll up half page

Syntax:

Ctrl+u

Examples:

Ctrl+u Move half page up

Notes:

Half page scroll

Ctrl+d

Navigation

Scroll down half page

Syntax:

Ctrl+d

Examples:

Ctrl+d Move half page down

Notes:

Half page scroll

Ctrl+f

Navigation

Page down

Syntax:

Ctrl+f

Examples:

Ctrl+f Move one page down

Notes:

Full page scroll

Ctrl+b

Navigation

Page up

Syntax:

Ctrl+b

Examples:

Ctrl+b Move one page up

Notes:

Full page scroll

f{char}

Navigation

Find next occurrence of character in line

Syntax:

f{character}

Examples:

fa Move to next 'a' in current line
f; Move to next ';' in current line

Notes:

Cursor lands on the character

F{char}

Navigation

Find previous occurrence of character in line

Syntax:

F{character}

Examples:

Fa Move to previous 'a' in current line
F( Move to previous '(' in current line

Notes:

Searches backwards in line

t{char}

Navigation

Move to (before) next occurrence of character

Syntax:

t{character}

Examples:

ta Move to just before next 'a'
t) Move to just before next ')'

Notes:

Cursor stops one character before target

T{char}

Navigation

Move to (after) previous occurrence of character

Syntax:

T{character}

Examples:

Ta Move to just after previous 'a'
T, Move to just after previous ','

Notes:

Searches backwards, stops after character

%

Navigation

Jump to matching bracket/parenthesis

Syntax:

%

Examples:

% Jump from ( to ) or from { to }

Notes:

Works with (), [], {}, and more

i

Insert Mode

Insert before cursor

Syntax:

i

Examples:

i Enter insert mode before cursor

Notes:

Most common way to start editing

I

Insert Mode

Insert at beginning of line

Syntax:

I

Examples:

I Move to start of line and enter insert mode

Notes:

Equivalent to ^i

a

Insert Mode

Insert after cursor

Syntax:

a

Examples:

a Enter insert mode after cursor

Notes:

Useful for appending

A

Insert Mode

Insert at end of line

Syntax:

A

Examples:

A Move to end of line and enter insert mode

Notes:

Equivalent to $a

o

Insert Mode

Open new line below

Syntax:

o

Examples:

o Create new line below and enter insert mode

Notes:

Creates line and enters insert mode

O

Insert Mode

Open new line above

Syntax:

O

Examples:

O Create new line above and enter insert mode

Notes:

Creates line and enters insert mode

s

Insert Mode

Substitute character

Syntax:

s

Examples:

s Delete character under cursor and enter insert mode
3s Delete 3 characters and enter insert mode

Notes:

Combination of x and i

S

Insert Mode

Substitute line

Syntax:

S

Examples:

S Delete entire line and enter insert mode

Notes:

Equivalent to cc

x

Delete

Delete character under cursor

Syntax:

x

Examples:

x Delete current character
5x Delete 5 characters

Notes:

Like pressing Delete key

X

Delete

Delete character before cursor

Syntax:

X

Examples:

X Delete character to the left
3X Delete 3 characters to the left

Notes:

Like pressing Backspace

dd

Delete

Delete entire line

Syntax:

dd

Examples:

dd Delete current line
3dd Delete 3 lines starting from current

Notes:

Line goes to default register

dw

Delete

Delete word

Syntax:

dw

Examples:

dw Delete from cursor to end of word
2dw Delete 2 words

Notes:

Includes trailing whitespace

de

Delete

Delete to end of word

Syntax:

de

Examples:

de Delete to end of current word

Notes:

Doesn't include trailing whitespace

d$

Delete

Delete to end of line

Syntax:

d$

Examples:

d$ Delete from cursor to end of line

Notes:

Also available as D

d0

Delete

Delete to beginning of line

Syntax:

d0

Examples:

d0 Delete from cursor to start of line

Notes:

Doesn't delete the character under cursor

dgg

Delete

Delete to beginning of file

Syntax:

dgg

Examples:

dgg Delete from cursor to start of file

Notes:

Deletes all lines above and current line

dG

Delete

Delete to end of file

Syntax:

dG

Examples:

dG Delete from cursor to end of file

Notes:

Deletes current line and all lines below

yy

Copy

Yank (copy) entire line

Syntax:

yy

Examples:

yy Copy current line
3yy Copy 3 lines starting from current

Notes:

Line goes to default register

yw

Copy

Yank word

Syntax:

yw

Examples:

yw Copy word from cursor
2yw Copy 2 words

Notes:

Includes trailing whitespace

ye

Copy

Yank to end of word

Syntax:

ye

Examples:

ye Copy to end of current word

Notes:

Doesn't include trailing whitespace

y$

Copy

Yank to end of line

Syntax:

y$

Examples:

y$ Copy from cursor to end of line

Notes:

Also available as Y

y0

Copy

Yank to beginning of line

Syntax:

y0

Examples:

y0 Copy from cursor to start of line

Notes:

Doesn't include character under cursor

ygg

Copy

Yank to beginning of file

Syntax:

ygg

Examples:

ygg Copy from cursor to start of file

Notes:

Copies all lines above and current line

yG

Copy

Yank to end of file

Syntax:

yG

Examples:

yG Copy from cursor to end of file

Notes:

Copies current line and all lines below

p

Paste

Paste after cursor

Syntax:

p

Examples:

p Paste after cursor or below current line
3p Paste 3 times

Notes:

Paste location depends on what was copied

P

Paste

Paste before cursor

Syntax:

P

Examples:

P Paste before cursor or above current line

Notes:

Opposite of p

cc

Change

Change entire line

Syntax:

cc

Examples:

cc Delete line and enter insert mode
2cc Change 2 lines

Notes:

Equivalent to S

cw

Change

Change word

Syntax:

cw

Examples:

cw Delete word and enter insert mode
3cw Change 3 words

Notes:

Delete and insert in one command

ce

Change

Change to end of word

Syntax:

ce

Examples:

ce Change to end of current word

Notes:

Doesn't include trailing whitespace

c$

Change

Change to end of line

Syntax:

c$

Examples:

c$ Delete to end of line and enter insert mode

Notes:

Also available as C

c0

Change

Change to beginning of line

Syntax:

c0

Examples:

c0 Delete to start of line and enter insert mode

Notes:

Doesn't delete character under cursor

/pattern

Search

Search forward for pattern

Syntax:

/pattern

Examples:

/hello Search for 'hello' going forward
/\d\+ Search for one or more digits (regex)

Notes:

Use Enter to execute search

?pattern

Search

Search backward for pattern

Syntax:

?pattern

Examples:

?hello Search for 'hello' going backward
?function Search for 'function' backward

Notes:

Use Enter to execute search

n

Search

Next search result

Syntax:

n

Examples:

n Go to next match in same direction

Notes:

Repeats last search in same direction

N

Search

Previous search result

Syntax:

N

Examples:

N Go to next match in opposite direction

Notes:

Repeats last search in opposite direction

*

Search

Search for word under cursor (forward)

Syntax:

*

Examples:

* Search forward for word under cursor

Notes:

Matches whole words only

#

Search

Search for word under cursor (backward)

Syntax:

#

Examples:

# Search backward for word under cursor

Notes:

Matches whole words only

:s/old/new/

Search & Replace

Substitute first occurrence in current line

Syntax:

:s/old/new/[flags]

Examples:

:s/hello/hi/ Replace first 'hello' with 'hi' in current line
:s/old/new/g Replace all 'old' with 'new' in current line

Notes:

Add 'g' flag for global replacement in line

:%s/old/new/g

Search & Replace

Substitute all occurrences in file

Syntax:

:%s/old/new/[flags]

Examples:

:%s/hello/hi/g Replace all 'hello' with 'hi' in entire file
:%s/old/new/gc Replace all with confirmation prompt

Notes:

% means entire file, g means global, c means confirm

:1,10s/old/new/g

Search & Replace

Substitute in range of lines

Syntax:

:start,ends/old/new/[flags]

Examples:

:1,10s/foo/bar/g Replace 'foo' with 'bar' in lines 1-10
:.,$s/old/new/g Replace from current line to end of file

Notes:

. means current line, $ means last line

:w

File Operations

Save file

Syntax:

:w [filename]

Examples:

:w Save current file
:w newfile.txt Save as newfile.txt

Notes:

Most common save command

:wq

File Operations

Save and quit

Syntax:

:wq

Examples:

:wq Save file and exit vim
ZZ Alternative: save and quit

Notes:

ZZ is equivalent shortcut

:q

File Operations

Quit

Syntax:

:q[!]

Examples:

:q Quit if no changes
:q! Quit without saving changes

Notes:

Use ! to force quit without saving

:e

File Operations

Edit file

Syntax:

:e [filename]

Examples:

:e file.txt Open file.txt
:e! Reload current file (discard changes)

Notes:

! reloads current file

:new

File Operations

Create new file in horizontal split

Syntax:

:new [filename]

Examples:

:new Create new unnamed file
:new file.txt Create new file named file.txt

Notes:

Opens in horizontal split

:vnew

File Operations

Create new file in vertical split

Syntax:

:vnew [filename]

Examples:

:vnew Create new unnamed file vertically
:vnew file.txt Create new file in vertical split

Notes:

Opens in vertical split

:split

Windows

Split window horizontally

Syntax:

:split [filename]

Examples:

:split Split current window horizontally
:split file.txt Split and open file.txt

Notes:

Also available as :sp

:vsplit

Windows

Split window vertically

Syntax:

:vsplit [filename]

Examples:

:vsplit Split current window vertically
:vsplit file.txt Split vertically and open file.txt

Notes:

Also available as :vsp

Ctrl+w w

Windows

Switch between windows

Syntax:

Ctrl+w w

Examples:

Ctrl+w w Move to next window

Notes:

Cycles through all windows

Ctrl+w h

Windows

Move to left window

Syntax:

Ctrl+w h

Examples:

Ctrl+w h Move to window on the left

Notes:

Directional window navigation

Ctrl+w j

Windows

Move to window below

Syntax:

Ctrl+w j

Examples:

Ctrl+w j Move to window below

Notes:

Directional window navigation

Ctrl+w k

Windows

Move to window above

Syntax:

Ctrl+w k

Examples:

Ctrl+w k Move to window above

Notes:

Directional window navigation

Ctrl+w l

Windows

Move to right window

Syntax:

Ctrl+w l

Examples:

Ctrl+w l Move to window on the right

Notes:

Directional window navigation

Ctrl+w q

Windows

Close current window

Syntax:

Ctrl+w q

Examples:

Ctrl+w q Close current window

Notes:

Equivalent to :q

Ctrl+w o

Windows

Close all other windows

Syntax:

Ctrl+w o

Examples:

Ctrl+w o Keep only current window

Notes:

Makes current window the only window

:tabnew

Tabs

Open new tab

Syntax:

:tabnew [filename]

Examples:

:tabnew Create new empty tab
:tabnew file.txt Open file.txt in new tab

Notes:

Opens new tab with file or empty buffer

:tabnext

Tabs

Go to next tab

Syntax:

:tabnext

Examples:

:tabnext Switch to next tab
gt Normal mode shortcut for next tab

Notes:

gt is the normal mode equivalent

:tabprev

Tabs

Go to previous tab

Syntax:

:tabprev

Examples:

:tabprev Switch to previous tab
gT Normal mode shortcut for previous tab

Notes:

gT is the normal mode equivalent

:tabclose

Tabs

Close current tab

Syntax:

:tabclose

Examples:

:tabclose Close current tab

Notes:

Closes tab and its windows

:tabonly

Tabs

Close all other tabs

Syntax:

:tabonly

Examples:

:tabonly Keep only current tab

Notes:

Closes all tabs except current

v

Visual Mode

Enter character-wise visual mode

Syntax:

v

Examples:

v Start selecting characters

Notes:

Select individual characters

V

Visual Mode

Enter line-wise visual mode

Syntax:

V

Examples:

V Start selecting entire lines

Notes:

Select complete lines

Ctrl+v

Visual Mode

Enter block-wise visual mode

Syntax:

Ctrl+v

Examples:

Ctrl+v Start selecting rectangular blocks

Notes:

Select rectangular blocks of text

gv

Visual Mode

Re-select last visual selection

Syntax:

gv

Examples:

gv Restore previous visual selection

Notes:

Useful for re-applying operations

u

Undo & Redo

Undo last change

Syntax:

u

Examples:

u Undo last edit
5u Undo last 5 changes

Notes:

Can be repeated with numbers

Ctrl+r

Undo & Redo

Redo change

Syntax:

Ctrl+r

Examples:

Ctrl+r Redo last undone change

Notes:

Opposite of undo

U

Undo & Redo

Undo all changes to current line

Syntax:

U

Examples:

U Restore line to original state

Notes:

Only works if you haven't moved away from line

"register

Registers

Use specific register

Syntax:

"[register][command]

Examples:

"ayy Copy line to register 'a'
"ap Paste from register 'a'
"0p Paste from yank register

Notes:

Registers a-z, 0-9, and special registers

:registers

Registers

Show all registers

Syntax:

:registers [register]

Examples:

:registers Show all register contents
:registers a Show register 'a' content

Notes:

Also available as :reg

m{letter}

Marks

Set mark at current position

Syntax:

m[a-zA-Z]

Examples:

ma Set mark 'a' at current position
mA Set global mark 'A'

Notes:

Lowercase marks are local to buffer, uppercase are global

'{letter}

Marks

Go to mark

Syntax:

'[a-zA-Z]

Examples:

'a Go to line with mark 'a'
`a Go to exact position of mark 'a'

Notes:

' goes to line start, ` goes to exact position

:marks

Marks

Show all marks

Syntax:

:marks [marks]

Examples:

:marks Show all marks
:marks abc Show marks a, b, and c

Notes:

Lists marks and their positions

q{letter}

Macros

Start recording macro

Syntax:

q[a-z]

Examples:

qa Start recording macro into register 'a'

Notes:

Press q again to stop recording

q

Macros

Stop recording macro

Syntax:

q

Examples:

q Stop current macro recording

Notes:

Only works when recording a macro

@{letter}

Macros

Play macro

Syntax:

@[a-z]

Examples:

@a Execute macro stored in register 'a'
5@a Execute macro 'a' 5 times

Notes:

Can be repeated with numbers

@@

Macros

Repeat last macro

Syntax:

@@

Examples:

@@ Repeat the last executed macro

Notes:

Convenient for repeating macros

aw/iw

Text Objects

Word text object

Syntax:

[operation][a/i]w

Examples:

daw Delete a word (including surrounding whitespace)
diw Delete inner word (word only)
caw Change a word

Notes:

'a' includes surrounding, 'i' is inner only

as/is

Text Objects

Sentence text object

Syntax:

[operation][a/i]s

Examples:

das Delete a sentence
vis Select inner sentence

Notes:

Sentence ends with ., !, or ?

ap/ip

Text Objects

Paragraph text object

Syntax:

[operation][a/i]p

Examples:

dap Delete a paragraph
vip Select inner paragraph

Notes:

Paragraph separated by blank lines

a)/i)

Text Objects

Parentheses text object

Syntax:

[operation][a/i])

Examples:

da) Delete text including parentheses
di) Delete text inside parentheses
vi( Select text inside parentheses

Notes:

Works with (, ), [, ], {, }, <, >

a'/i'

Text Objects

Quote text object

Syntax:

[operation][a/i][quote]

Examples:

da' Delete text including single quotes
di' Delete text inside single quotes
vi" Select text inside double quotes

Notes:

Works with ', ", and `

zf

Folding

Create fold

Syntax:

zf[motion]

Examples:

zf5j Fold 5 lines down
zf% Fold to matching bracket

Notes:

Creates manual fold

zo

Folding

Open fold under cursor

Syntax:

zo

Examples:

zo Open fold at cursor

Notes:

Opens one level of folding

zc

Folding

Close fold under cursor

Syntax:

zc

Examples:

zc Close fold at cursor

Notes:

Closes one level of folding

za

Folding

Toggle fold under cursor

Syntax:

za

Examples:

za Open if closed, close if open

Notes:

Convenient for toggling folds

zR

Folding

Open all folds

Syntax:

zR

Examples:

zR Open all folds in buffer

Notes:

Opens all levels of folding

zM

Folding

Close all folds

Syntax:

zM

Examples:

zM Close all folds in buffer

Notes:

Closes all levels of folding

VIM Editor Mastery Guide

VIM Modes

  • Normal Mode: Default mode for navigation and commands
  • Insert Mode: For typing text (enter with i, a, o)
  • Visual Mode: For selecting text (v, V, Ctrl+v)
  • Command Mode: For file operations (start with :)
  • Press Esc to return to Normal mode

Essential Workflow

  1. vim filename - Open file
  2. i - Enter insert mode to edit
  3. Type your content
  4. Esc - Return to normal mode
  5. :w - Save file
  6. :q - Quit (or :wq to save and quit)

Quick Navigation

  • h j k l - Left, down, up, right
  • w b e - Word navigation
  • ^ $ 0 - Line navigation
  • gg G - File navigation
  • f t - Character search in line

Power Features

  • :split :vsplit - Window management
  • :tabnew gt gT - Tab management
  • qa @a @@ - Macro recording/playback
  • ma 'a `a - Marks and jumps
  • \"a - Named registers

Text Objects

  • diw daw - Delete inner/around word
  • di( da( - Delete inside/around parentheses
  • di\" da\" - Delete inside/around quotes
  • dip dap - Delete inner/around paragraph
  • Combine with c (change) or y (yank)

Visual Mode Power

  • v - Character-wise selection
  • V - Line-wise selection
  • Ctrl+v - Block-wise selection
  • gv - Re-select last selection
  • Use with operators: d y c etc.

Search & Replace

  • /pattern - Search forward
  • ?pattern - Search backward
  • n N - Next/previous match
  • * # - Search word under cursor
  • :%s/old/new/g - Replace all in file

Common Gotchas

  • Always check which mode you're in
  • Use :q! to force quit without saving
  • Remember u for undo, Ctrl+r for redo
  • Practice hjkl navigation instead of arrow keys
  • Learn text objects for efficient editing

🎯 Pro Tips

  • Customize VIM with ~/.vimrc configuration file
  • Use . to repeat the last command
  • Learn to think in "verb + noun" (operator + text object)
  • Master a few commands deeply rather than memorizing everything
  • Practice regularly - VIM proficiency comes with muscle memory

📚 What is Vim?

Vim (Vi Improved) is a highly configurable, powerful text editor built to make creating and changing text very efficient. It's an enhanced version of the vi editor that comes with most Unix systems. Originally created by Bram Moolenaar in 1991, Vim has become one of the most popular text editors among programmers, system administrators, and power users worldwide.

🚀 Key Features

  • ✓ Modal editing: Different modes for different tasks (normal, insert, visual, command)
  • ✓ Highly efficient: Minimal mouse usage, keyboard-driven workflow
  • ✓ Extensible: Thousands of plugins and customization options
  • ✓ Cross-platform: Available on virtually every operating system
  • ✓ Lightweight: Fast startup and low resource usage
  • ✓ Powerful search & replace: Regular expressions and advanced text manipulation

💡 Why Choose Vim?

  • • Speed: Once mastered, editing becomes incredibly fast
  • • Ubiquity: Available on servers, embedded systems, and all platforms
  • • Consistency: Same interface everywhere, no matter the environment
  • • Powerful: Handle large files and complex editing tasks efficiently
  • • Free & Open Source: No licensing costs, community-driven development
  • • Career value: Highly valued skill in tech industry

🎯 Who Uses Vim?

Software Developers

For coding in any programming language with powerful text manipulation and plugin ecosystem

System Administrators

For editing configuration files, scripts, and logs on servers without GUI

Writers & Content Creators

For distraction-free writing, markdown editing, and document processing

🚀 Getting Started with Vim

1. Installation

sudo apt install vim (Ubuntu/Debian) • brew install vim (macOS) • Pre-installed on most Linux/Unix systems

2. Learn the Basics

Start with vimtutor command for interactive tutorial • Practice modal editing • Master basic navigation

3. Build Muscle Memory

Use Vim daily for small tasks • Focus on efficiency over speed initially • Gradually learn advanced features

Remember: Vim has a steep learning curve, but the investment pays off with dramatically increased editing efficiency. Start with the basics and gradually build your skillset. This cheat sheet is your companion on that journey! 🎯