DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Writing and editing

Correcting mistakes

You can correct mistakes in vi by using the x key to delete the character under the cursor.

You need to be in command mode (press <Esc>) to use x to delete -- otherwise, you just end up with a lot of x's. After you have deleted the unwanted text, insert the correct text by pressing i. Text is inserted to the left of the cursor.

Try editing the first line of weekrep:

  1. Go to your home directory by typing cd and pressing <Enter>.

  2. Type vi weekrep and press <Enter> to open weekrep in vi.

  3. Using the down arrow or the j key, go to the line starting with ``This week ...''

  4. Using the right arrow or the space bar, move the cursor to 5 and press x. The 5 disappears.

  5. Using the right arrow or space bar, move the cursor to 10. Press x twice to delete the 10. The line should now read ``This week I met with of our distributors.''

  6. Using the left arrow or the h key, move back to the space between ``with'' and ``of''. The cursor should be on the space between the two words.

  7. Press i to insert, then type 6.

  8. Press <Esc>. The line should now read ``This week I met with 6 of our distributors.''

  9. Use the right arrow or the space bar to move the cursor to the space between ``our'' and ``distributors''.

  10. Press i and type 11. The line should now read ``This week I met with 6 of our 11 distributors.''

  11. Press <Esc> to go into command mode, then press : to get the : prompt at the bottom of the screen.

  12. Type x at the : prompt to save the file and exit vi.

Q: I am finding it hard to tell when I am in insert mode and when I am in command mode -- is there any way to make this easier?

A: If you are in vi, you can press <Esc> to go to command mode, type :, and then type set showmode to set the showmode option. The showmode option prints the mode you are in at the bottom of your screen whenever you are in input (insert) mode. The mode it prints will be APPEND, CHANGE, INSERT, OPEN, or REPLACE, depending on your current action.

If you always want to use the showmode option, create a file in your home directory called .exrc that contains the following line:

set showmode
vi looks for the .exrc file each time it starts, so this is where you should put frequently used vi options. For more information about vi options, see the section on vi in ``Editing files''.

Q: Suppose I type a colon and then change my mind and decide I do not want to use the : prompt?

A: Press <Del> to cancel the command and return to editing the file. Your terminal may beep or flash at you; ignore it. You can also type <Esc> if you have not typed a valid command, but, if you have typed a command and you press <Esc>, vi performs the command you typed.

Q: Why does my terminal keep beeping (or flashing) at me?

A: vi sends a beep to your terminal (some terminals use a flash) in a number of instances. Two common times vi beeps at you are when you press <Esc> when you are already in command mode, and when you try to move beyond the last text on a line.

When you first start using vi, your terminal beeps a lot. You can safely ignore this.


Next topic: Printing files
Previous topic: Moving to a particular line

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005