UNIX

10 Useful VI commands

Here are a few VI commands that I use allot and find very useful.
Once in command mode (by pressing ESC) enter:
:wq
To Save or Write and document and quit VI
:w
To save the document
:q!
To quite the document WITHOUT saving.
J
Capital J will join next line down on to the end of your current line.
G
Capital Go will take you to the end of document.
CTRL+G
Control G displays the current line number
:n
Enter a colon then a number to go to that line number
:mn
Move the current line to line number n
:%s/old_string/new_string/g
old_string is the the string you want to replace
new_string is the new string you want to replace the old string with
g to make the changes globally through the whole document.
If you want to remove a string, simply leave out the new_string so the command like like this: :%s/old_string//g
:%s/^/new_string/g
The symbol above the number 6 on the keyboard means the start of the line.
new_string is the string you want to add to the start of every line.