- 论坛徽章:
- 0
|
as cc. One of the best uses for s is to change one character to
several characters.
R ("large" replace) is useful when you want to start changing text,
but you don't know exactly how much. For example, instead of
guessing whether to say 3cw or 4cw, just type R and then enter your
replacement text.
2.4.1 Numeric Arguments for Insert Commands
Except for o and O, the above insert commands (plus i and a) take
numeric prefixes. With numeric prefixes, you might use the
commands i, I, a, and A to insert a row of underlines or alternating
characters. For example, typing 50i*ESC inserts 50 asterisks, and
typing 25a*- ESC appends 50 characters (25 pairs of asterisk and
hyphen). It's better to repeat only a small string of characters.[4]
[4] Very old versions of vi have difficulty repeating the insertion of more than one line's worth of text.
With a numeric prefix, r replaces that many characters with a
repeated instance of a single character. For example, in C or C++
code, to change || to &&, you would place the cursor on the first
pipe character, and type 2r&.
You can use a numeric prefix with S to substitute several lines. It's
quicker and more flexible, though, to use c with a movement
command.
A good case for using the s command with a numeric prefix is when
you want to change a few characters in the middle of a word.
Typing r wouldn't be correct, but typing cw would change too much
text. Using s with a numeric prefix is usually the same as typing R.
There are other combinations of commands that work naturally
together. For example, ea is useful for appending new text to the
end of a word. It helps to train yourself to recognize such frequent
combinations so that they become automatic.
2.5 Joining Two Lines with J
Sometimes while editing a file you will end up with a series of
short lines that are difficult to scan. When you want to merge two
lines into one, position the cursor anywhere on the first line, and
press J to join the two lines.
Suppose your file practice reads: |
|