Select Page

Basic vi Commands

To launch the vi Editor:
– Open the Terminal (CLI).

To edit or view a current file:
– Type vi filename.extension (e.g vi vnstat_Jan.sh where vnstat_Jan is the filename while sh refers to shell script extension).

 

KeystrokesAction
iInsert (goes into insert/input mode).
aAppend.
AAppend at EOL (End Of Line).
EscEnd input.
uUndo last command.
UUndo all changes to the entire line.
oOpen a new line (goes into insert mode).
dd
3dd
Delete line
Delete 3 lines.
DDelete contents of line after the cursor.
CDelete contents of a line after the cursor and insert new text. Press ESC key to end insertion.
dw
4dw
Delete word
Delete 4 words.
cwChange word.
xDelete character at the cursor.
rReplace character.
ROverwrite characters from cursor onward.
sSubstitute one character under cursor continue to insert.
SSubstitute entire line and begin to insert at the beginning of the line.
~Change case of individual character.
(press esc) :wSave the file but keep it open.
(press esc) :q
(press esc) :q!
Quit without saving.
(press esc) :wqSave the file and quit.

Other Articles