- 论坛徽章:
- 0
|
\( \)
Saves the pattern enclosed between \( and \) into a special
holding space or "hold buffer." Up to nine patterns can be
saved in this way on a single line. For example, the pattern:
\(That\) or \(this\)
saves That in hold buffer number 1 and saves this in hold
buffer number 2. The patterns held can be "replayed" in
substitutions by the sequences \1 to \9. For example, to
rephrase That or this to read this or That, you could enter:
:%s/\(That\) or \(this\)/\2 or \1/
You can also use the \n notation within a search or substitute
string:
:s/\(abcd\)\1/alphabet-soup/
[4]
changes abcdabcd into alphabet-soup.
[4] This works with vi, nvi, and vim, but not with elvis 2.0, vile 7.4, or vile 8.0.
\< \>
Matches characters at the beginning (\<) or at the end (\>) of
a word. The end or beginning of a word is determined either
by a punctuation mark or by a space. For example, the
expression \<ac will match only words that begin with ac,
such as action. The expression ac\> will match only words
that end with ac, such as maniac. Neither expression will
match react. Note that unlike \(...\), these do not have to
be used in matched pairs.
~
Matches whatever regular expression was used in the last
search. For example, if you searched for The, you could
search for Then with /~n. Note that you can use this pattern
only in a regular search (with /).[5] It won't work as the
pattern in a substitute command. It does, however, have a
similar meaning in the replacement portion of a substitute
command.
[5] This is a rather flaky feature of the original vi. After using it, the saved search pattern is set to
the new text typed after the ~, not the combined new pattern, as one might expect. Also, none of
the clones behaves this way. So, while this feature exists, it has little to recommend its use. |
|