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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.2 Eye to Eye with vi41• :7,.w! filename writes lines from line 7 up to and including the currentline to the named file, clobbering any previous c<strong>on</strong>tents (think of the “!”as meaning “and d<strong>on</strong>’t argue with me!”).• :q quits, provided you’ve saved your changes (e.g., with :w).• :q! quits without saving any changes to the file.• :n doesn’t exit vi, but moves <strong>on</strong> to the next file if you started up withmore than <strong>on</strong>e file to edit (e.g., vi Fir.java Pine.java). When you’vereached the last file in the list, you need to quit—for example, with :q.2.2.2 Search and ReplaceWe’ve menti<strong>on</strong>ed searching for a string with / or ?, but what about replacing?Once you’ve located a string with /, you can use cw or C or R or other suchcommands to effect the change. Search for the next occurrence with n, and thenyou can repeat your change (the last c, s, r, and so <strong>on</strong>) by typing the period“.” that will repeat that last substituti<strong>on</strong>, insert, and so <strong>on</strong>.But what if you want to make 225 substituti<strong>on</strong>s? Typing n.n.n.n.n.n.would get old after a while. Here, the ex mode, like any good command line,comes to the rescue to help with repetitive tasks.If we want to search and replace all occurrences of <strong>on</strong>e string for another,we can use the command:1,$s/<strong>on</strong>e string/another/Almost all ex commands take an address range, that is, the lines of the fileover which they will operate. If just <strong>on</strong>e line number is given, the commandwill operate <strong>on</strong> that <strong>on</strong>e line. Two numbers, separated by commas, representthe start and end lines—inclusive—of the operati<strong>on</strong>. The first line is line 1, soa 0 as line number would mean “before the first line.” The line where the cursoris currently located is just “.” (a period). The last line of the file can be representedby the dollar sign ($). You can even do some simple math <strong>on</strong> theaddresses—for example, .+2 meaning the sec<strong>on</strong>d line in fr<strong>on</strong>t of the cursor’scurrent line.TIPThere is a shortcut for the 1,$ address range. Use % to mean “all lines”—forexample, %s/<strong>on</strong>e string/another/.

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

Saved successfully!

Ooh no, something went wrong!