13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.2 Eye to Eye with vi39In both cases, when you hit the top or bottom of the file, vi will wrap andkeep searching from the opposite end, though a warning message will appearin the status bar.OK, enough navigati<strong>on</strong>. Let’s start modifying text.Copy and paste operati<strong>on</strong>s can be d<strong>on</strong>e easily <strong>on</strong> whole lines. Just yankand put the lines. You can yank a single line or several at a time (e.g., 7y) andthen a single put (p) will deposit a copy just after the current line (the linewhere your cursor sits). If you want to put the text before, not after, the currentline, use uppercase P.Go ahead. Try it <strong>on</strong> the file you’re practicing <strong>on</strong>. It’s the best way to geta feel for what we’re describing here.Cut and paste operati<strong>on</strong>s involve deleting the lines, not just copying them.This gets us into our third and final kind of syntax in vi, the double lettercommands. Use dd to delete a line. Try it and you will find that the line yourcursor is <strong>on</strong> just got deleted, and the cursor now rests comfortably <strong>on</strong> the nextline. To paste that line back, use the same p or P that we used for to put thelines that we had copied (a.k.a. “yanked”) above.But why the dd? What’s with the double letters? Think of “delete” for dand then add another letter to describe how much you want to delete—dw for“delete word” or dW for “delete the bigger words” (see above). So why dd for aline? We d<strong>on</strong>’t know for a fact, but we suspect that it’s just for speed. You canalso follow a d with the h, j, k, or l of our cursor movement, and that willdelete either a character or a line in the appropriate directi<strong>on</strong>.A faster way (<strong>on</strong>e keystroke, not two) to delete a single character is withthe x key. And of course 5x, or 27x, will delete multiple characters. But ifyou’re deleting many characters you will probably get it d<strong>on</strong>e faster by deleting“words” (dw or dW).Another powerful way to delete text is to delete it from the cursor up to aspecific character. The sequence dt; will delete from the cursor up to (but notincluding) the semicol<strong>on</strong> <strong>on</strong> the current line. If there is no semicol<strong>on</strong>, vi willbeep, and no change will be made. To delete from the cursor up to and includingthe semicol<strong>on</strong>, use df;.Everything you’ve just learned about delete is also true for change, the cin vi. You can combine it with itself (cc) to change a whole line. You cancombine it with w to change a word (cw), or you can change from the cursorup to the next semicol<strong>on</strong> (ct;), and so <strong>on</strong>.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!