Command |
Description |
Save and Quit |
:w |
Save changes |
:wq or :x |
Save changes and quit |
:q! |
Quit without saving |
u |
Undo last change |
Move Cursor |
^ |
Move cursor to the beginning of current line |
$ |
Move cursor to the end of current line |
w |
Move cursor to the beginning of next word |
b |
Move cursor to the beginning of preceding word |
Delete |
dw |
Delete single word beginning with the character under cursor |
dd |
Delete current line |
d$ |
Delete the remaining of line beginning with the character under cursor |
:1,$d$ |
Delete all the lines |
:1,Nd |
Delete 1 to N lines |
:Ndd |
Delete the next N lines, including the current line |
Copy and Paste |
yw |
Copy a word |
yy |
Copy current line |
Nyy |
Copy the next N lines, including the current line |
:1,Ny |
Copy 1 to N lines |
p |
Paste buffer after the current line |
:r filename |
Read file named filename and insert after current line |
Search and Replace |
/string |
Search for a string. Press n, cursor moves to the next occurrence; Press N, cursor moves to the preceding occurrence. |
:s/old/new/g |
Find each occurrence of ‘old’ on the current line and replace it with ‘new’ |
:%s/old/new/g |
Find each occurrence of ‘old’ throughout the file and replace it with ‘new’ |
Display |
:set number |
Display line numbers |
:vsplit filename |
Split vi vertically and display file named filename on the left half |
ctrl-w ctrl-w |
Move cursor between split screens |