The Linux Page - vi commands

HOME
Back to the Linux Page

List of tools for the vi text editor
created 10/5/07
This page is a reference for commands in the vi text editor - nothing more

Navigation commands
h moves cursor to the left
j moves cursor down one line
k moves cursor up one line
l moves cursor to the right
w moves cursor to next word
b moves cursor to previous word
e moves cursor to 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 move cursor to beginning of line
$ move cursor to end of line
[Ctrl]+g display where cursor is in the file
n[Shift]+g moves cursor to line number n
fx finds next occurrence of x within the current line
Fx finds previous occurrence of x within the current line
/ finds next occurrence of pattern within the file
?pattern finds previous occurrence of pattern within the file
n finds next occurrence of pattern when followed by / or ?
Editing commands
yy copies (yanks) current line
nyy copies n number of lines
P pastes the data above the current line
p pastes the data below the current line
rx replaces current character with x
x deletes character at the cursor position
nx delets n number of characters
dd delete current line
ndd delete n number of lines
dw delete current word
ndw delete n number of words
cw change current word
ncw change nnumber of words
cc change current line
ncc change n number of lines
J joins the line below to the current line
u undoes the last change made
.(dot) repeats the last change made

Commands within vi
i puts vi in insert mode with cursor in current position
a puts vi in insert mode with cursor in next position
A puts vi in insert mode with cursor at end of line
I insert mode with cursor at beginning of line
o opens new line under current position
O opens new line above current position
[Esc] switch to command mode
:w saves file
:w foo.txt saves file as foo.txt
:e bar.txt opens bar.txt
:q closes the file
:wq saves changes and closes file
:q! closes file without saving changes
:!"command" runs the shell command "command"