Vi Commands
The following commands can be used in the vi text editor while in Command Mode.
To switch from Insert Mode to Command Mode, press the Escape (Esc) key.
Cursor Movement
Command | Function |
h | One space to the left |
j | One space to up |
k | One space down |
l | One space to the right |
<Return> | Beginning of new line |
- | Beginning of previous line |
^ | Beginning of current line |
$ | End of current line |
<Space> | 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
Command | Function |
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 |
Delete | Overwrites last character during text insertion |
Escape | Stops text insertion, returns to command mode |
Change Commands
Command | Function |
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 |
Screen Commands
Command | Function |
h | One space to the left |
j | One space to up |
k | One space down |
l | One space to the right |
<Return> | Beginning of new line |
- | Beginning of previous line |
^ | Beginning of current line |
$ | End of current line |
<Space> | 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 |
Other Tips
Command | Function |
"vi myfile" | Creates or opens a file in vi, where "myfile" is the name of the file
(type this command at the standard Unix prompt to open the vi text editor) |
ZZ | Saves changes to the current file and exits vi |
:wq | Writes changes to the current file and quits the editing session |
:q! | Quits the editing session without saving changes |
No comments:
Post a Comment