Wednesday, 30 December 2015

Vi Commands

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

CommandFunction
hOne space to the left
jOne space to up
kOne space down
lOne 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
nGBeginning of line n
bBeginning of current word
wBeginning of next word
eEnd of current word
Control - eScroll forward
Control - bScroll backward
/patternFirst occurence of pattern
nNext occurence of pattern
NPrevious occurence of pattern
/Repeats last pattern search

Text Insertion and Deletion

CommandFunction
AAppends text at the end of the line
iInserts text to the left of the cursor
IInserts text at the beginning of the line
oOpens a new line below the current line for text to be inserted
OOpens a new line above the current line for text to be inserted
xDeletes character at cursor position
XDeletes character left of cursor position
ddDeletes current line
dwDeletes current word
d)Deletes rest of sentence
D or d$Deletes from cursor to end of line
PPuts back text from the previous delete
rxReplaces selected character with x
uUndoes last change
URestores current line
:R myfileAppends file "myfile" to current file at current cursor position
DeleteOverwrites last character during text insertion
EscapeStops text insertion, returns to command mode

Change Commands

CommandFunction
cwChanges characters of current word until escape key is pressed
c$Changes text up to the end of the line
C or ccChanges remaining text on the current line until escape key is pressed
~Changes case of the current character
xpTransposes the current and following characters
JJoins current line with the next line
sDeletes current character and enters insertion mode
rxReplaces current character with x
RReplaces the following characters until escape key is pressed
yyPuts current line in a buffer without deleting the line
pPlaces the line stored in buffer after the current position of the cursor

Screen Commands

CommandFunction
hOne space to the left
jOne space to up
kOne space down
lOne 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
nGBeginning of line n
bBeginning of current word
wBeginning of next word
eEnd of current word
Control - eScroll forward
Control - bScroll backward
/patternFirst occurence of pattern
nNext occurence of pattern
NPrevious occurence of pattern
/Repeats last pattern search

Other Tips

CommandFunction
"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)
ZZSaves changes to the current file and exits vi
:wqWrites changes to the current file and quits the editing session
:q!Quits the editing session without saving changes

No comments: