Text Editor Mode

The aim is to change the contents of the file and vi offers a very large set of commands to help in this process. This section will focus on adding text, changing the existing text and deleting the text. At the end of this section you will have the knowledge to create any text file desired.

When entering text, multiple lines can be entered by using the RETURN key. If a typing mistake needs to be corrected and you are on the entering text on the line in question. You can use the BACKSPACE key to move the cursor over the text. The different implementations of vi behave differently. Some just move the cursor back and the text can still be viewed and accepted. Others will remove the text as you backspace. If the text is visible and you use the ESC key when on the line you have backspaced on the text after the cursor will be cleared. Use your editor to become accustomed to its behaviour.

a: Append some text from the current cursor position
A: Append at the end of the line
i: Insert text to the Left of the cursor
I: Inserts text to the Left of the first non-white character on current line
o: Open a new line and adds text Below current line
O: Open a new line and adds text Above the current line

vi has a small set of delete commands which can be enhanced with the use of command modifiers.

x: Delete one character from under the cursor
dw: Delete from the current position to the end of the word
dd: Delete the current line.
D: Delete from the current position to the end of the line

On occasions you may need to undo the changes. The following commands restore the text after changes.

u: Undo the last command
U: Undo the current line from all changes on that line

not only allows you to undo changes, it can reverse the undo. Using the command 5dd delete 5 lines then restore the lines with u . The changes can be restored by the u again.

Supported By

File Browser Reference
Department FHERIS
University of Galway
HEA Logo