ex Commands

This section summarizes the ex commands used from the colon prompt in vi.

Command Syntax

:[address]command[options]

Address Symbols

Address

Includes

1,$

All lines in the file

x,y

Lines x through y

x;y

Lines x through y, with current line reset to x

0

Top of file

.

Current line

n

Absolute line number n

$

Last line

%

All lines; same as 1,$

x-n

n lines before x

x+n

n lines after x

-[n]

One or n lines previous

+[n]

One or n lines ahead

’ x

Line marked with x (single quote)

’ ’

Previous mark (two single quotes)

/pat/ or ?pat?

Ahead or back to the line where pat matches

Command Option Symbols

Symbol

Meaning

!

A variant form of the command

count

Repeat the command count times

file

Filename: % is current file, # is previous file

Alphabetical List of Commands

The following table of ex commands covers both standard ex commands and selected commands specific to Vim. Commands covered in Vim—vi Improved are omitted here.

Full nameCommandVim only
Abbrev

ab [string text]

 
Append

[address] a[!] text .

 
Args

ar

 
Args

args files …

✓
Bdelete

[num] bd[!] [num]

✓
Buffer

[num] b[!] [num]

✓
Buffers

[num] buffers[!]

✓
Center

[address] ce [width]

✓
Change

[address]c[!] text .

 
Chdir

cd directory

 
Copy

[address] co destination

 
Delete

[address] d [buffer]

 
Edit

e [!][+n] [filename]

 
File

f [filename]

 
Global

[address]g[!]/pattern/[commands]

 
Insert

[address]i[!] text .

 
Join

[address]j[!][count]

 
K (mark)

[address] k char

 
Left

[address] le [count]

✓
List

[address] l [count]

 
Map

map char commands

 
Mark

[address

Get vi and Vim Editors Pocket Reference, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.