Vi has 3 basic modes of operation: command (default), input, last line mode.
You can return to command mode from input or last line mode pressing Esc.
Key | Cursor movement |
---|---|
w | Forward one word. |
b | Back one word. |
e | To the end of the current word. |
$ | To the end of the line. |
0(zero) | To the beginning of the line. |
^ | To the first non-white space character on the line. |
G | Goes to the last line of the file. |
lG | Goes to the first line of the file. |
Ctrl + F | Pages forward one screen. |
Ctrl + B | Pages back one screen. |
Ctrl + D | Scrolls down one-half screen. |
Ctrl + U | Scrolls up one-half screen. |
Ctrl +L | Refreshes the screen. |
Command | Function |
---|---|
R | Overwrites or replaces characters on the line at and to the right of cursor. To terminate press Esc. |
C | Changes or overwrites characters from cursor to the end of the line. |
s | Substitutes a string for a character at the cursor. |
x | Deletes a character at the cursor. |
dw | Deletes a word or part of the word to the right of the cursor. |
dd | Deletes the line containing the cursor. |
D | Deletes the line from the cursor to the right end of the line. |
:n, nd | Deletes lines n-n. Example :2,80d deletes lines 2-80. |
Command | Function |
---|---|
cw | Changes or overwrites characters at the cursor location to the end of that word. |
r | Replaces the character at the cursor with one other character. |
J | Join the current line and the line below. |
xp | Transposes the character at the cursor and the character to the right of the cursor. |
~ | Changes the case of the letter, either uppercase or lowercase, at the cursor. |
u | Undo the previous command. |
. | Repeats previous command. |
Command | Function |
---|---|
/string | Searches forward for the string from cursor. |
?string | Searches backward for the string. |
n | Searches for the next occurrence of the string. Use this command after searching for a string. |
N | Searches for the previous occurrence of the string. Use this command after searching for a string. |
:%s/old/new/g | Searches for the old string and replaces it iwth the new string globally. |
Command | Function |
---|---|
yy | Yanks a copy of line |
p | Puts yanked or deleted text under the line containing the cursor. |
P | Put |
:n,n co n | Copies lines n-n and puts them after line n. Example :1,5 co 8 copies lines 1-5 and puts them after line 8. |
:n,n m n | Moves lines n-n to line n. Example :1,5 m 8 moves lines 1-5 to the line 8. |
Command | Function |
---|---|
:w | Saves the file with changes by writing to the disk |
:w new_file | Writes the contents of the buffer to new_file. |
wq | Saves the changed file and quits editor vi. |
:x | Saves the changed file and quits editor vi. |
ZZ | Saves the changed file and quits editor vi. |
:q! | Quits without saving changes. |
Command | Function |
---|---|
:set nu | Shows line numbers. |
:set nonu | Hides line numbers. |
:set ic | Instructs searches to ignore case. |
:set noic | Instructs searches to be case sensitive. |
set list | Display invisible characters. |
:set showmode | Display the current mode of operation. |
:set noshowmode | Turns off the mode of operation display. |
:set | Displays all the vi variables that are set. |
:set all | Display all vi variables and their values. |
Command | Function |
---|---|
:set nu | Shows line numbers. |
:set nonu | Hides line numbers. |
:set ic | Instructs searches to ignore case. |
:set noic | Instructs searches to be case sensitive. |
set list | Display invisible characters. |
:set showmode | Display the current mode of operation. |
:set noshowmode | Turns off the mode of operation display. |
:set | Displays all the vi variables that are set. |
:set all | Display all vi variables and their values. |
Was this information helpful to you? You have the power to keep it alive.
Each donated € will be spent on running and expanding this page about UNIX Shell.
We prepared for you video course Marian's BASH Video Training: Mastering Unix Shell, if you would like to get much more information.
Thank you. Marian Knezek