#print More Alteration - Targets When we first looked at the 'dd' and 'cc' commands, we said that they were special cases of more general commands. In fact, 'd' and 'c' are the basis for some of the most powerful commands in vi. We'll only talk about the 'd' command here, but it's all applicable to 'c' as well. The idea behind targets is to somehow combine the simple idea of deleting things with the movement commands, yielding a whole set of new commands. For example, the 'w' command will move the cursor ahead one word. The 'dw' command will delete everything from where we are up to the beginning of the next word. ')' moves forward a sentence; 'd)' deletes a sentence. You can use this for practically all movement commands, including all of the following: - return space ^ $ 0 H L M w b e W B E ( ) f F t T ; , / ? n N Type 'ready' and try out these commands. Take your time and experiment!! #user #create Targets The idea behind targets is to somehow combine the simple idea of deleting things with the movement commands, yielding a whole set of new commands. For example, the 'w' command will move the cursor ahead one word. The 'dw' command will delete everything from where we are up to the beginning of the next word. ')' moves forward a sentence; 'd)' deletes a sentence. You can use this for practically all movement commands, including all of the following: - return space ^ $ 0 H L M w b e W B E ( ) f F t T ; , / ? n N Now you may be able to see the usefulness of the 't' and 'T' commands. Recall that 'tx' moves the cursor to the character before the next 'x' on the line. Therefore, 'dtx' will delete everything up to, but not including, the next 'x' on the line. 'dfx', on the other hand, will delete everything up to and including the 'x'. Both commands have their uses. Remember that all of these targets can also be used with the 'c' command. That is, 'c3w' will allow you to change the next three words. When you try this, note that vi doesn't actually erase the words and then put you into insert mode (That's a lot of redrawing that may not be necessary). It instead places a dollar sign at the last character to be changed. When you hit Escape to get out of insert mode, the line will be fixed up. Try it! In the next three lessons, we'll see other commands which, like 'c' and 'd', can use targets. ------------------------------------------------------------------------------- # cat /usr/share/learn/vi/longtext >> Targets vi Targets #next 5.2 10