Impossible tri-bar

Digital Phenomena - Your first stop for internet consultancy 
Advanced vi

Page 5 — Cutting and Pasting

By now, you should be comfortable with moving around a file rapidly, searching for text, and replacing text. It's time to work on a more complex text manipulation: cutting and pasting text. Let's work with the example below.

    Let's say you're trapped on a planet with a number of very large and very hungry Klingons. Your only hope is to call for a Starfleet captain. Who do you call? Kirk, because he'd kick Klingon butt? Picard, because the Klingon Empire honored its treaty with the Federation? Or Janeway, because she'd take you back to the Quadrant Delta where there aren't any Klingons?

First, I'm going to move the cursor to the phrase "Quadrant Delta." Any Trekker worth his or her tricorder knows it's the "Delta Quadrant." So I'm going to swap the order of the two words by moving my cursor to the "Q" in Quadrant; typing "dw" to delete the word; moving my cursor to the space right after the "a" in "Delta"; and hitting "p." This tells the editor to put the deleted text ("Quadrant") in the space immediately after the cursor.

I could have done this a little differently using the "P" key. "P" puts text immediately before the cursor; if I had decided that P was the way to go, I would move my cursor to the "D" in Delta, type "dw" to delete "Delta," move my cursor to the "Q" in Quadrant, and type "P" to paste the text.

Let's say I just want to add a little emphasis to the example and point out that these Klingons are giant, mutant Klingons. Lacking decent adjectives, I'm just going to say that the Klingons are "very very very large" Klingons. This means copying the word "very" and pasting it a few times. Type "yw" (this copies the word), move the cursor to the place where you want to begin pasting "very," and type "p" to your heart's content.

If you look at the yw syntax a little more closely, you'll see that it resembles the syntax for deleting: yw means to yank (copy) a word, dw means to delete it. This resemblance continues all the way through the whole family of yanking commands: You can type "yy" to yank a whole line of text, "y[[" to yank a whole section, and so on.

next page»

|Home|About Us|Services|Search|
W3C validatedW3C validated CSSCompatible with all browsers