Prev | Current Page 231 | Next

Christopher Negus

"Linux Bible, 2008 Edition: Boot up to Ubuntu, Fedora, KNOPPIX, Debian, openSUSE, and 11 Other Distributions"

(I chose the words Local and Remote to search for, but you can use any appropriate
words.)
 :g/Local??”Searches for the word Local and prints every occurrence of that line from
the file. (If there is more than a screenful, the output is piped to the more command.)
 :s/Local/Remote??”Substitutes Remote for the word Local on the current line.
 :g/Local/s//Remote??”Substitutes the first occurrence of the word Local on every
line of the file with the word Remote.
 :g/Local/s//Remote/g??”Substitutes every occurrence of the word Local with the
word Remote in the entire file.
 :g/Local/s//Remote/gp??”Substitutes every occurrence of the word Local with the
word Remote in the entire file, and then prints each line so that you can see the changes
(piping it through more if output fills more than one page).
Using Numbers with Commands
You can precede most vi commands with numbers to have the command repeated that number of
times. This is a handy way to deal with several lines, words, or characters at a time. Here are some
examples:
 3dw??”Deletes the next three words.
 5cl??”Changes the next five letters (that is, it removes the letters and enters input mode).
 12j??”Moves down 12 lines.
Putting a number in front of most commands just repeats those commands.


Pages:
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243