The fundamental UNIX editor is called vi. It is a primitive editor, but it will be found on every UNIX system. There are just a few commands that one needs to learn at first, and they will be sufficient to write simple files.
There are essentially three Modes in vi, the Insert Mode where one is typing in new text, the Edit Mode where one is modifying text that is already there, and the Command Mode where one is interacting with the operating system with actions like reading and writing files.
INSERT Mode - For adding text to a file
The most common ways to enter the Insert Mode are:
i - Starts inserting in front of the current cursor position
I - Starts adding at the front of the line
a - Starts adding after the cursor
A - Starts adding at the end of the line
o - Starts opening a new line underneath the cursor
O- Starts opening a line above the cursor.
Esc - to get out of insert mode
EDIT Mode
Generally for moving the cursor and deleting stuff. In the Edit Mode, the keys do not type letters, but do other actions such as cursor movement, deletions, copying lines, etc.
Cursor Movement :
h - Moves cursor left one space
j - Moves cursor down one line
k - Moves cursor up one line
l - Moves cursor right one space
w - Moves the cursor a full word at a time to the right
b - Moves the cursor back to the left a word at a time
^ - Moves the cursor to the front of a line
$ - Moves the cursor to the end of a line
ctrl+f - Moves the cursor forward a full page of text at a time
ctr+b - Moves the cursor backward a full page of text at a time
Modifying Text
x - Deletes the character under the cursor
dd - Deletes the line where the cursor is located
n dd - Delete n consecutive lines ( n is an integer)
r - Replaces the character under the cursor with the next thing typed
J - Joins current line with the one below
u - Undoes the last edit operation
ctrl+r - Redo (Undoes the last undo operation)
Cut/Copy/Paste
yy - Copies a line, 5yy copies 5 lines
p - pastes the copied text on the line below the cursor
P - pastes the copied text on the line above the cursor
COMMAND Mode - For interacting with the operating system.
To enter the Command Mode, a colon " : " must precede the actual command.
: r <file> reads a file from disk into the vi editor
: w <file> writes current file to disk
: wq writes the file and quits vi
: q! quits without writing