#print Basic Alteration - Insert and Delete I So now you can move around nearly to your heart's content. Wouldn't it be nice if you could change something? In the next two lessons you'll see how to make basic changes to a file: inserting and deleting characters and lines. Inserting and deleting text are just a matter of moving to the right place and using the right command. We'll be looking at these six commands: i a These are the most common insertion commands. 'i' will allow you to insert text before the character the cursor is on and 'a' will append it after the current character. I A These are for inserting text at the beginning of the current line and appending it to the end of said line. x X These are the commands for deleting characters. 'x' will delete the character the cursor is on and 'X' gets rid of the character before the cursor. Type 'ready' now to learn more about inserting and deleting. #user #create Insert1 Inserting text takes four steps: 1) Move to the proper place in the file. 2) Type the correct insertion command (i, I, a, or A). This puts you into 'insert' mode. 3) Enter the new text. 4) Hit the Escape key. This brings you back out of insert mode. The insertion commands, again, are as follows: i inserts before the current character a appends (i.e. inserts after the current character) I inserts before the beginning of the current line A appends text after the end of the current line Try inserting some text now anywhere in the file. Don't touch anything past the dashed line, though. Deleting text is merely a matter of moving the cursor to the characters to be deleted and hitting x once per character. They should disappear. You can also use the X command, which deletes the character right before the current one. This doesn't appear to get used too frequently, however. Try deleting some text now, anywhere in the file. Still don't touch things after the dashed line, though. When you're done, do the exercise below. -------------------------------------------------------------------------- EXERCISE Delete the words 'blort' and 'gronk' below. Don't delete the dashes or equals signs. Then insert the word 'blather' between the equals signs. Be sure to save your changes before you leave the editor. -blort==gronk- #create Answer -=blather=- # vi Insert1 grep =- Insert1 > Attempt #cmp Attempt Answer #succeed Not bad... Not bad at all. It looks like you pick up this stuff pretty quickly. #fail Accidents will happen. Give it another try. This time spend a little more time practicing before you do the exercise. If you managed to do it but couldn't remember how to save the file, try it again anyway. You save your work by using the :w command. Type 'ready' when the learn program types a percent sign. #next 3.2 10