vi Command Reference

Posted On 2008-10-25 by FortyPoundHead
Tags: Tutorial Linux Commandline Tip Linux
Views: 1874

A table of commands used in the Unix-based vi editing program. Commands include moving the cursor, text insertion and deletion, screen commands, and change commands.

Moving the Cursor
h One space to the left
j One space to up
k One space down
l One space to the right
  Beginning of new line
- Beginning of previous line
^ Beginning of current line
$ End of current line
  Forward one space
nG Beginning of line n
b Beginning of current word
w Beginning of next word
e End of current word
Control - e Scroll forward
Control - b Scroll backward
/pattern First occurence of pattern
n Next occurence of pattern
N Previous occurence of pattern
/ Repeats last pattern search
Text Insertion and Deletion
a Appends text to the right of the cursor
A Appends text at the end of the line
i Inserts text to the left of the cursor
I Inserts text at the beginning of the line
o Opens a new line below the current line for text to be inserted
O Opens a new line above the current line for text to be inserted
x Deletes character at cursor position
X Deletes character left of cursor position
dd Deletes current line
dw Deletes current word
d) Deletes rest of sentence
D or d$ Deletes from cursor to end of line
P Puts back text from the previous delete
rx Replaces selected character with x
u Undoes last change
U Restores current line
:R myfile Appends file "myfile" to current file at current cursor position
DEL Overwrites last character during text insertion
ESC Stops text insertion, returns to command mode
Screen Commands
Control - I Reprints current screen
Control - L Exposes one more line at top of screen
Control - E Exposes one more line at bottom of screen
Control - F Pages forward one screen
Control - B Pages back one screen
Control - D Pages down half a screen
Control - U Pages up half a screen
Change Commands
cw Changes characters of current word until escape key is pressed
c$ Changes text up to the end of the line
C or cc Changes remaining text on the current line until escape key is pressed
~ Changes case of the current character
xp Transposes the current and following characters
J Joins current line with the next line
s Deletes current character and enters insertion mode
rx Replaces current character with x
R Replaces the following characters until escape key is pressed
yy Puts current line in a buffer without deleting the line
p Places the line stored in buffer after the current position of the cursor

About the Author

FortyPoundHead has posted a total of 1974 articles.

Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links