#print Basic Alteration - Insert and Delete II Now we'll see how to change things at a larger scale than individual characters. Suppose you wanted to put a blank line into your file. You could use the A command to start inserting at the end of the line, hit return and then hit Escape. That would do it, but there's an easier way. The o and O commands 'open' a new line either after or before the current line. You can then add more text if you like and hit Escape when you're done to get out of insert mode. 'o' opens a blank line after the current one and O does it before the current one. To get rid of a line, just move to that line and hit 'dd'. That's really two d's there, not one. This is a single case of a more general command which we'll look at later. If you want to change a line, i.e. delete the old one and type a new one in its place, move to the line and type 'cc'. We'll see more of the d and c commands later. Type 'ready' (as usual) to practice these commands and learn some others. #user #create Insert2 The commands for opening up new blank lines are o (to open one after the current line) and O (to open one before the current line). The dd command will delete the current line and the cc command will both delete it and let you type in a replacement. You can try these out on the sample text after the dashed line below. You may notice when you use the dd command that the lines don't seem to go away entirely. There always seems to be a line with an at-sign (@) on it where the old lines were. This only happens on so-called 'dumb' terminals which can't quickly delete lines. Those lines aren't really in the file (as you'll see if you try to move onto them), they're just a convenience so that vi doesn't have to take the time to redraw a lot of your screen every time you delete a line. You can use the ^R command to 'repair' the screen at any time. Try it! Another handy command for changing text is the r command to replace a character. If you only need to turn one character into another, just move the cursor to the character in question and hit r followed by the new character. This will replace the old one. If you want to overwrite more than one character, use the R command. You move to the first character to be overwritten, type R, type the new text over the old, and hit Escape to leave overwrite mode. The last command we'll look at here is the s command, for substituting characters. Suppose there is a character you want to replace with more than one other characters. Just move to the old character, type s, type the new characters, and hit Escape to leave substitution mode. If you need to substitute for more than one character, you can just precede the s command with a count. For example, to replace 3 characters with 5 others, move to the first character to be replaced, type 3s, type the 5 new characters and hit Escape. We've just looked at a lot of commands at once. Spend enough time practicing them so that you'll remember them well. They're the commands you'll end up using most frequently. --------------------------------------------------------------- # cat /usr/lib/learn/vi/longtext >> Insert2 vi Insert2 #next 3.3 10