Читать книгу Linux Bible - Christopher Negus - Страница 156
Using ex mode
ОглавлениеThe vi
editor was originally based on the ex
editor, which didn't let you work in full-screen mode. However, it did enable you to run commands that let you find and change text on one or more lines at a time. When you type a colon and the cursor goes to the bottom of the screen, you are essentially in ex
mode. The following are examples of some of those ex
commands for searching for and changing text. (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 first occurrence of 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 less if output fills more than one page).