If you can see this check that
vi example
-
% vi text_file
You should see the following screen with the cursor at the top left.
_ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
"test_file" [New file] |
|
The "~" character in the window indicates that that line currently does not
exist. As the file is new no line exists, so this image gives you an idea what
an empty file looks like in vi.
- Press i (insert before the cursor) to start entering text. This places you in
text input mode. The screen does not change and you do not press return after
pressing i.
- Type the following sample text. include the mistakes; you will correct them later. If you type
a mistake that is not in the sample, use the backspace key to move back over the incorrect text, and then retype it.
As you add text,
the lines wit the tilde characters
will scroll down towards
the botom of the screeen.
- Press ESC (escape key). Pressing ESC enters you into command mode, which means you can no longer
enter text; instead you can command the cursor to move within the file.
- Type :wq followed by return. Typing a colon while in command mode
opens a command line at the bottom of your screen. When you type the wq command
the w writes test_file to the disk, and the q tells vi to quit.
- Re-enter test_file to correct the mistakes as follows:
% vi test_file
The command is the same as before, but instead of opening a new test file,
vi finds the existing file test_file. The screen clears and you should see the following:
As you add text, |
the lines wit the tilde characters |
will scroll down towards |
the botom of the screeen. |
~ |
~ |
~ |
~ |
~ |
~ |
~ |
"test_file" 4 lines, 103 characters |
|
To correct the two mistakes in the fourth line ("botom" and "screeen"), execute
the following:
- Press j three times to move the cursor down to the first character in the
forth line.
- Press l (lowercase L) several times to move the cursor right until the cursor
is at the 't' in botom. If you pass 't', press h to move the cursor left.
- Press i to insert text before the cursor, and type 't' to spell bottom correctly.
- Press ESC to end the text input mode and return you to the command mode.
Next, correct "screeen" which is also in the fourth line:
- Press l until the cursor is at the first e in screen.
- Press x to delete the extra e. If you make a mistake, such as deleting more than one
character, press U (uppercase U) to undo the changes you made.
After deleting text you do not have to press ESC as you have not left the command mode.
Now, correct the mistake 'wit' in the second line:
- Press k twice to move the cursor up to the second line. Press
h to move the cursor left. Position the cursor at the 't' in wit. If
you pass the 't', press l to move the cursor right.
- Press a to append text. Pressing a exists command mode, so whatever you type is added to the text.
- Type h to spell 'with' correctly.
- Press ESC to return to the command mode.
- You now have corrected the mistakes in text_file and can now
exit vi in one of two ways:
- :wq
- To exit vi and save the corrections
- :q!
- To exit vi without saving the corrections
Linuxzoo created by Gordon Russell.
@ Copyright 2004-2024 Edinburgh Napier University