📄 e6
字号:
.H1Special Characters.H2.PGYou may have noticed that things just don't work right when you usedsome characters like ``.'', ``*'', ``$'', and others incontext searches and the substitute command.The reason is rather complex, although the cure is simple.Basically,.uledtreats these characters as special, with special meanings.For instance,.ulin a context search or the first string of the substitute command only,\*. means ``any character,'' not a period, so.X1/x\*.y/.X2means ``a line with an x,.ulany character,and a y,''.ulnotjust ``a line with an x, a period, and a y.''~A complete list of the special charactersthat can cause trouble is the following:.X1^ \*. $ [ * \\.X2.ulWarning:The backslash character \\ is special to.uled.For safety's sake, avoid it where possible.If you have to use one of the special charactersin a substitute command,you can turn off its magic meaning temporarilyby preceding it with the backslash.Thus.X1s/\\\\\\\*.\\*/backslash dot star/.X2will change ``\\\*.*'' into ``backslash dot star''..PGHere is a hurried synopsis of the other special characters.First, the circumflex `` ^ ''signifiesthe beginning of a line.Thus.X1/^string/.X2finds ``string'' only if it is at the beginning of a line:it will find.X1string.X2but not.X1the string....X2The dollar-sign ``$'' is just the opposite of the circumflex;it means the end of a line:.X1/string$/.X2will only find an occurrence of ``string''that is at the end of some line.This implies, of course,that.X1/^string$/.X2will find only a line that contains just ``string'',and.X1/^\*.$/.X2finds a line containing exactly one character..PGThe character ``\*.'', as we mentioned above,matches anything;.X1/x\*.y/.X2matches any of.X1x+yx-yx yx\*.y.X2This is useful in conjunction with ``*'',which is a repetition character;``a*'' is a shorthand for ``any number of a's,''so ``\*.*'' matches any number of anythings.This is used like this:.X1s/\*.*/stuff/.X2which changes an entire line,or.X1s/\*.*,//.X2which deletes all characters in the line up to andincluding the last comma.(Since``\*.*'' finds the longest possible match,this goes up to the last comma.).PG``['' is used with ``]'' to form ``character classes'';for example,.X1/[1234567890]/.X2matches any single digit _any one of the characters inside the braceswill cause a match..PGFinally, the ``&'' is another shorthand character -it is used only on the right-hand part of a substitute commandwhere it means ``whatever was matched on the left-hand side''.It is used to save typing.Suppose the current line contained.X1Now is the time.X2and we wanted to put parentheses around it.We could just retype the line, butthis is tedious.Or we could say.X1s/^/(/s/$/)/.X2using our knowledge of ``^'' and ``$''.But the easiest way uses the ``&'':.X1s/\*.*/(&)/.X2This says ``match the whole line, and replace itby itself surrounded by parens.''~The ``&'' can be used several times in a line;considerusing.X1s/\*.*/&? &!!/.X2to produce.X1Now is the time? Now is the time!!.X2.PGWe don't have to match the whole line, of course:if the buffer contains.X1the end of the world.X2we could type.X1/world/s//& is at hand/.X2to produce.X1the end of the world is at hand.X2Observe this expression carefully,for it illustrates how to take advantage of.uledto save typing.The string ``/world/''found the desired line;the shorthand ``//'' found the sameword in the line;and the ``&'' saved us from typing it again..PGThe ``&'' is a special character only withinthe replacement text of a substitute command,and has no special meaning elsewhere.We can turn off the special meaning of ``&''by preceding it with a ``\\'':.X1s/ampersand/\\&/.X2will convert the word ``ampersand'' into the literal symbol``&''in the current line.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -