You are on page 1of 3

Page 1

vi editor commands
Two modes of the vi editor
• Command mode: Can perform commands in the vi editor
• Editing (Insert) mode: Can type information in the vi editor

Why learn the vi editor?


• The vi editor is the most frequently used editor in all flavors of Linux and
UNIX
• It is also useful in case the flavor of Linux/UNIX does not have a graphical
interface

Navigation Commands
Command Description
h Moves cursor to the left
j Moves cursor down a line
k Moves cursor up a line
l Moves cursor to the right
w Moves cursor to the next word
b Moves cursor to the previous word
e Moves cursor to the end of the word
<ctrl> + d (or D) Scroll down half-screen
<ctrl> + u (or U) Scroll up half-screen
<ctrl> + F Scroll down one page
<ctrl> + B Move back one page
0 (zero) Move cursor to the beginning of the line
$ Move cursor to the end of the line
<ctrl> + g Displays the status (where the cursor is in the file)

A “cheat sheet” of commands for the vi editor


Page 2

vi editor commands

Modification Commands
Command Description
yy Copies current line
Nyy Copys n amount of lines
P Pastes data below current line
p Pastes data above current line
rx Replaces the current character with a specific character
rtext<esc> Replaces characters at the current cursor position with the text
x Deletes the character at the current cursor position
dd Delete a line
dw Delete a word
cw Changes a word
cc Changes a line
j Joins lines
u Undoes the last change made
. (dot) Repeats the last change made
fx Finds the specific character on the current line after the current cursor
position
Fx Finds the specific character on the current line before the current
cursor position
/pattern Finds the next line containing the specified pattern
?pattern Finds the previous line containing the specified pattern.

A “cheat sheet” of commands for the vi editor


Page 3

vi editor commands

Insert/Command Commands
Command Description
i Puts vi in insert mode – cursor stays in current position
a Puts vi in insert mode – moves cursor to the next position
A Puts vi in insert mode – moves cursor to the end of the line
I Puts vi in insert mode – moves cursor to the beginning of the line
o Puts vi in insert mode – Inserts a blank line below the current line
O Puts vi in insert mode – inserts a blank line above the current line
<esc> Switch from insert mode to command mode

File Processing Commands


Command Description
:q! Closes without saving
:q Closes
:w<filename> Saves as <filename>
:wq Saves and closes
:e<filename> Open a file
:!<command> Run a shell command

A “cheat sheet” of commands for the vi editor

You might also like