Site Administration Page 5 - Vi 101 |
Next up, deleting and copying text. To delete a single character, position the cursor under it, make sure you're in command mode, and type to delete it. To delete a word, hit which stands for "delete word". Nuking an entire line is accomplished with while novelists with writers block will appreciate the thoughtfulness of the and commands, which delete everything from the current cursor position to the beginning and end of the file respectively. Oops - you didn't just try that last one, did you? Not to worry - vi also comes with a very handy "undo" command, which can be accessed by hitting whenever you feel the urge to undo your previous mistakes. And since undo and redo go together like strawberries and cream, you might want to check out the "redo" command, which allows you to repeat past actions by typing When you delete something in vi, the deleted text usually finds its way to a temporary buffer in memory, where it resides until it is replaced. This deleted text can be re-inserted into your document with the "put" command; if you've been following along, you already know that the "put" command is accessed with Go on - try it. Delete a line, move down to a new paragraph, and put it back in a different place. Simple - and equivalent to the cut-paste functionality available in other editors. In case you'd like to insert the deleted text *above* the current cursor position, simply use instead of What about copy-paste? Also pretty easy - vi uses the "yank" command to copy text in much the same way as the delete command is used to delete text. To yank a particular word, try while yanks a complete line and places it in the temporary buffer, ready to be "put" somewhere new. You're probably wondering what all this has to do with shampoo. Absolutely nothing - this particular lesson was originally titled "Cut, Copy, Paste...", but I thought "Lather, Rinse, Repeat..." had a nicer ring to it... This article copyright Melonfire 2000. All rights reserved.
blog comments powered by Disqus |