Vi Commands

From rbachwiki
Jump to navigation Jump to search

Open file

vi filename
i Changes to insert mode
esc Changes back to command mode while in insert mode
w # writes file
q # quite file
:wq # this will write the line and quite

When in insert mode, you can use the keyboard to type text as required, but when finished you must press the Esc key to return to command mode to perform other functions via keys on the keyboard. Quit Editor- quit the vi editor by pressing the : character and entering q!, which then returns the user to the shell prompt:

w, W Moves the cursor forward one word to the beginning of the next word 
e, E Moves the cursor forward one word to the end of the next word 
b, B Moves the cursor backward one word
53G Moves the cursor to line 53 
G Moves the cursor to the last line in the document 
0, ^ Moves the cursor to the beginning of the line 
$ Moves the cursor to the end of the line 
X Deletes the character the cursor is on 
3x Deletes three characters starting from the character the cursor is on 
dw Deletes one word starting from the character the cursor is on 
d3w, 3dw Deletes three words starting from the character the cursor is on dd Deletes one whole line starting from the line the cursor is on 
d3d, 3dd Deletes three whole lines starting from the line the cursor is on 
d$ Deletes from cursor character to the end of the current line 
d^, d0 Deletes from cursor character to the beginning of the current line 
yw Copies one word (starting from the character the cursor is on) into a temporary buffer in memory for later use
y3w, 3yw Copies three words (starting from the character the cursor is on) into a temporary buffer in memory for later use
yy Copies the current line into a temporary buffer in memory for later use 
y3y, 3yy Copies three lines (starting from the current line) into a temporary buffer in memory for later use 
y$ Copies the current line from the cursor to the end of the line into a temporary buffer in memory for later use 
y^, y0 Copies the current line from the cursor to the beginning of the line into a temporary buffer in memory for later use 
p Pastes the contents of the temporary memory buffer underneath the current line 
P Pastes the contents of the temporary memory buffer above the current line 
J Joins the line underneath the current line to the current line 
Ctrl+g Displays current line statistics 
u Undoes the last function (undo) 
. Repeats the last function (repeat) 
/pattern Searches for the first occurrence of pattern in the forward direction 
?pattern Searches for the first occurrence of pattern in the reverse direction 
n Repeats the previous search in the forward direction 
N Repeats the previous search in the reverse direction

Centos OS