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).
Keystrokes | Action |
---|---|
i | Insert (goes into insert/input mode). |
a | Append. |
A | Append at EOL (End Of Line). |
Esc | End input. |
u | Undo last command. |
U | Undo all changes to the entire line. |
o | Open a new line (goes into insert mode). |
dd 3dd | Delete line Delete 3 lines. |
D | Delete contents of line after the cursor. |
C | Delete contents of a line after the cursor and insert new text. Press ESC key to end insertion. |
dw 4dw | Delete word Delete 4 words. |
cw | Change word. |
x | Delete character at the cursor. |
r | Replace character. |
R | Overwrite characters from cursor onward. |
s | Substitute one character under cursor continue to insert. |
S | Substitute entire line and begin to insert at the beginning of the line. |
~ | Change case of individual character. |
(press esc) :w | Save the file but keep it open. |
(press esc) :q (press esc) :q! | Quit without saving. |
(press esc) :wq | Save the file and quit. |