⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pattern.cnx

📁 Vim 中文文档
💻 CNX
📖 第 1 页 / 共 3 页
字号:
|/\%$|	\%$	\%$	文件尾 |/zero-width||/\%#|	\%#	\%#	光标位置 |/zero-width||/\%l|	\%23l	\%23l	在第 23 行内匹配 |/zero-width||/\%c|	\%23c	\%23c	在第 23 列内匹配 |/zero-width||/\%v|	\%23v	\%23v	在虚拟第 23 列内匹配 |/zero-width|字符类 {not in Vi}:|/\i|	\i	\i	标识符字符 (见 'isident' 选项)|/\I|	\I	\I	像 "\i",但不包括数字字符|/\k|	\k	\k	关键字字符 (见 'iskeyword' 选项)|/\K|	\K	\K	像 "\k",但不包括数字字符|/\f|	\f	\f	文件名字符 (见 'isfname' 选项)|/\F|	\F	\F	像 "\f",但不包括数字字符|/\p|	\p	\p	可打印字符 (见 'isprint' 选项)|/\P|	\P	\P	像 "\p",但不包括数字字符|/\s|	\s	\s	空白字符; <Space> 和 <Tab>|/\S|	\S	\S	非空白字符:\s 之反|/\d|	\d	\d	数字:				[0-9]|/\D|	\D	\D	非数字:			[^0-9]|/\x|	\x	\x	十六进制数字:			[0-9A-Fa-f]|/\X|	\X	\X	非十六进制字符:			[^0-9A-Fa-f]|/\o|	\o	\o	八进制字符:			[0-7]|/\O|	\O	\O	非八进制字符:		[^0-7]|/\w|	\w	\w	单词字符:			[0-9A-Za-z_]|/\W|	\W	\W	非单词字符:		[^0-9A-Za-z_]|/\h|	\h	\h	单词首字符:		[A-Za-z_]|/\H|	\H	\H	非单词首字符:	[^A-Za-z_]|/\a|	\a	\a	英文字母字符:		[A-Za-z]|/\A|	\A	\A	非英文字母字符:	[^A-Za-z]|/\l|	\l	\l	小写字符:		[a-z]|/\L|	\L	\L	非小写字符:	[^a-z]|/\u|	\u	\u	大写字符:		[A-Z]|/\U|	\U	\U	非大写字符		[^A-Z]|/\_|	\_x	\_x	其中 x 可以是以上任意一个字符:包括行尾的字符类(字符类结束)|/\e|	\e	\e	<Esc>|/\t|	\t	\t	<Tab>|/\r|	\r	\r	<CR>|/\b|	\b	\b	<BS>|/\n|	\n	\n	行尾|/~|	~	\~	上次给出的替换字符串|/\1|	\1	\1	第一个 \(\) 匹配的字符{not in Vi}|/\2|	\2	\2	如 "\1",但用第二个 \(\)	   ...|/\9|	\9	\9	如 "\1",但用第九个 \(\)								*E68*|/\z1|	\z1	\z1	仅用于语法加亮,见 |:syn-ext-match|	   ...|/\z1|	\z9	\z9	仅用于语法加亮,见 |:syn-ext-match|	x	x	一个没有特殊含义的字符匹配其自身|/[]|	[]	\[]	[] 内指定的任何字符之一|/\%[]| \%[]	\%[]	一个可以选择性匹配的原列表|/\c|	\c	\c	忽略大小写|/\C|	\C	\C	匹配大小写|/\m|	\m	\m	对之后模式中字符打开 'magic' 选项|/\M|	\M	\M	对之后模式中字符关闭 'magic' 选项|/\v|	\v	\v	对之后模式中字符设定 'magic' 选项为 "very magic"|/\V|	\V	\V	对之后模式中字符设定 'magic' 选项为 "very nomagic"|/\Z|	\Z	\Z	ignore differences in Unicode "combining characters".			Useful when searching voweled Hebrew or Arabic text.Example			matches ~\<\I\i*		或\<\h\w*\<[a-zA-Z_][a-zA-Z0-9_]*			一个标识符 (例如,在一个 C 程序里)。\(\.$\|\. \)		一个英文句号后跟 <EOL> 或一个空格。[.!?][])"']*\($\|[ ]\)	一个匹配英文句子结尾的模式。几乎和 ")" 定义的一样。cat\Z			匹配 "cat" 和 "ca虁t" ("a" 后跟 0x0300)			不匹配 "c脿t" (字符 0x00e0),虽然它们看起来一样。==============================================================================3. 魔术							*/magic*某些字符在模式中是原文被采用的。它们匹配自身。然而,当前面有一个反斜杠时,这些字符具有特殊的含义。另外一些字符即使没有反斜杠也代表特殊的意思。它们反而需要一个反斜杠来匹配其自身。一个字符是否被当原文采用取决于 'magic' 选项以及下面将解释的条目。							*/\m* */\M*使用 "\m" 会使得其后的模式的解释方式就如同设定了 'magic' 选项一样。而且将忽略'magic' 选项的实际值。使用 "\M" 会使得其后的模式的解释方式就如同设定了 'nomagic' 选项一样。							*/\v* */\V*使用 "\v" 会使得其后的模式中所有 '0'-'9', 'a'-'z', 'A'-'Z' 和 '_' 之外的字符都被当做特殊字符解释。"very magic"使用 "\V" 会使得其后的模式中只有反斜杠有特殊的意义。"very nomagic"例子:跟着:	  \v	   \m	    \M	     \V		匹配 ~		'magic' 'nomagic'	  $	   $	    $	     \$		匹配行尾	  .	   .	    \.	     \.		匹配任何字符	  *	   *	    \*	     \*		前面原的任意次重复	  ()	   \(\)     \(\)     \(\)	组成为一个原	  |	   \|	    \|	     \|		分割 alternatives	  \a	   \a	    \a	     \a		字母字符	  \\	   \\	    \\	     \\		反斜杠(原意)	  \.	   \.	    .	     .		英文句号(原意)	  \{	   {	    {	     {		'{' (原意)	  a	   a	    a	     a		'a' (原意){only Vim supports \m, \M, \v and \V}建议始终将 'magic' 选项保持在缺省值 -  'magic'。这可以避免移植性的麻烦。要使模式不受该选项值的影响,在模式前面加上 "\m" 或 "\M"。==============================================================================4. 多项						*pattern-multi-items*一个匹配原子后面可以跟一个表示匹配该原子次数和方式的修饰。这被称为多项。在|/multi| 可以看到一个综述。如果一个匹配原子可能会匹配一个空串的话,其后就不能使用多项修饰符。这是因为那样可能会引起死循环。如果你还是要试试的话,你会得到一个错误信息: >	*, \+ or \{ operand could be empty<						*/star* */\star* *E56**	(在没有设定 'magic' 使用 \*)	匹配 0 或更多个前面的原子,近可能多地匹配。	例子     'nomagic'	匹配 ~	a*	   a\*		"", "a", "aa", "aaa", 等.	.*	   \.\*		任意,包括空串,不包括行尾	\_.*	   \_.\*	匹配至缓冲结束	\_.*END	   \_.\*END	匹配至缓冲中最后一次出现 "END" 处,包括该				"END"	例外: 当 "*" 被使用在模式的开头或者紧跟在 "^" 之后时它匹配星号字符。	要当心,重复匹配 "\_." 会包括大量的文本,因而可能会花很长时间。例如,	"\_.*END" 匹配从当前位置开始到文件中最后一次出现 "END" 的地方。因为 "*"	会尽可能多的匹配,这会先跳过到文件结束前的所有行然后反方向逐字查找	"END"。							*/\+* *E57*\+	匹配一个或更多前面的匹配原。尽可能多。{not in Vi}	例		匹配 ~	^.\+$		任意空行	\s\+		一个以上的空白字符							*/\=*\=	匹配 0 或 1 个前面的匹配原。尽可能多。 {not in Vi}	例		匹配 ~	foo\=		"fo" 和 "foo"							*/\?*\?	和 \= 一样。不能和 "?" 命令中使用。{not in Vi}						*/\{* *E58* *E60* *E554*\{n,m}	匹配 n 至 m 个前面的匹配原。尽可能多。\{n}	匹配 n 个前面的匹配原。\{n,}	匹配至少 n 个前面的匹配原。尽可能多。\{,m}	匹配 0 至 m 个前面的匹配原。尽可能多。\{}	匹配 0 个以上前面的匹配原。尽可能多。(如 *)							*/\{-*\{-n,m}	匹配 n 至 m 个前面的匹配原。尽可能少。\{-n}	匹配 n 个前面的匹配原。\{-n,}	匹配至少 n 个前面的匹配原。尽可能少。\{-,m}	匹配 0 至 m 个前面的匹配原。尽可能少。\{-}	匹配 0 个以上前面的匹配原。尽可能少。(如 *)	{Vi does not have any of these}	n 和 m 是正的十进制数	如果一个 "-" 紧接在 "{" 之后,那么最短匹配优先算法将被启用 (见下面的例子)。      	In particular, "\{-}" is	特别的,"\{-}" 和 "*" 一样,只不过使用了最短匹配优先算法。但 是: 一个	先前开始的匹配拥有比最短匹配高的优先级: "a\{-}b" 匹配 "xaaab" 中的 "aaab"。	例子			匹配 ~	ab\{2,3}c		"abbc" 或 "abbbc"	a\{5}			"aaaaa".	ab\{2,}c		"abbc", "abbbc", "abbbbc", 等	ab\{,3}c		"ac", "abc", "abbc" 或 "abbbc".	a[bc]\{3}d		"abbbd", "abbcd", "acbcd", "acccd", 等。	a\(bc\)\{1,2}d		"abcd" 或 "abcbcd"	a[bc]\{-}[cd]		"abcd" 中的 "abc"	a[bc]*[cd]		"abcd" 中的 "abcd"	} 之前可以 (也可以不) 加一个反斜杠: \{n,m\}.							*/\@=*\@=	以零宽度匹前面的匹配原。{not in Vi}	象 Perl 中的 '(?=pattern)".	例			匹配 ~	foo\(bar\)\@=		"foobar" 中的 "foo"	foo\(bar\)\@=foo	空							*/zero-width*	当使用 "\@=" (或 "^", "$", "\<", "\>") 时匹配中不包括任何字符。这些	字符仅仅是被用来检查能否构成一个匹配的。这很容易搞错。因为后续的项	会被在同样位置作匹配。上面的最后一个例子不会匹配 "foobarfoo",因为	Vim 会尝试在 "bar" 匹配的同样地方匹配 "foo"。	Note 使用 "\&" 同使用 "\@=" 是一样的: "foo\&.." 和 "\(foo\)\@=.."	一样。但用 "\&" 容易些,你可以省了那些括号。							*/\@!*\@!	Matches with zero width if the preceding atom does NOT match at the	current position |/zero-width| {not in Vi}	象 Perl 中的 '(?!pattern)"。	例如			匹配 ~	foo\(bar\)\@!		任意后面不带 "bar" 的 "foo"	a.\{-}p\@!		"a", "ap", "app", 等。后面不带 "p"	Using "\@!" is tricky, because there are many places where a pattern	does not match.  "a.*p\@!" will match from an "a" to the end of the	line, because ".*" can match all characters in the line and the "p"	doesn't match at the end of the line.  "a.\{-}p\@!" will match any	"a", "ap", "aap", etc. that isn't followed by a "p", because the "."	can match a "p" and "p\@!" doesn't match after that.	You can't use "\@!" to look for a non-match before the matching	position: "\(foo\)\@!bar" will match "bar" in "foobar", because at the	position where "bar" matches, "foo" does not match.  To avoid matching	"foobar" you could use "\(foo\)\@!...bar", but that doesn't match a	bar at the start of a line. Use "\(foo\)\@<!bar".							*/\@<=*\@<=	Matches with zero width if the preceding atom matches just before what	follows. |/zero-width| {not in Vi}	Like '(?<=pattern)" in Perl, but Vim allows non-fixed-width patterns.	Example			matches ~	\(an\_s\+\)\@<=file	"file" after "an" and white space or an				end-of-line	For speed it's often much better to avoid this multi.  Try using "\zs"	instead |/\zs|.  To match the same as the above example:		an\_s\+\zsfile	"\@<=" and "\@<!" check for matches just before what follows.	Theoretically these matches could start anywhere before this position.	But to limit the time needed, only the line where what follows matches	is searched, and one line before that (if there is one).  This should	be sufficient to match most things and not be too slow.	The part of the pattern after "\@<=" and "\@<!" are checked for a	match first, thus things like "\1" don't work to reference \(\) inside	the preceding atom.  It does work the other way around:	Example			matches ~	\1\@<=,\([a-z]\+\)	",abc" in "abc,abc"							*/\@<!*\@<!	Matches with zero width if the preceding atom does NOT match just	before what follows.  Thus this matches if there is no position in the	current or previous line where the atom matches such that it ends just	before what follows.  |/zero-width| {not in Vi}	Like '(?<!pattern)" in Perl, but Vim allows non-fixed-width patterns.	The match with the preceding atom is made to end just before the match	with what follows, thus an atom that ends in ".*" will work.	Warning: This can be slow (because many positions need to be checked	for a match).	Example			matches ~	\(foo\)\@<!bar		any "bar" that's not in "foobar"	\(\/\/.*\)\@\<!in	"in" which is not after "//"							*/\@>*\@>	象匹配一整个模式一样匹配前面的原。{not in Vi}	类似 Perl 中的 '(?>pattern)".	例子		匹配 ~	\(a*\)\@>a	空 ("a*" 用尽了所有的 "a",后面不可能有了)	这象匹配一整个模式一样匹配前面的原。如果无法匹配,不会用较短的子模式	来重试。注意观察这两者的不同:"a*b" 和 "a*ab" 都匹配 "aaab",但是后者	中的 "a*" 仅仅匹配前两个 "a"。"\(a*\)\@>ab" 不会匹配 "aaab",因为 "a*"	匹配了 "aaa" (尽可能多个 "a"),导致 "ab" 无法匹配。==============================================================================5.  普通匹配原					*pattern-atoms*一个普通匹配原可能是:							*/^*^	在模式起点或在 "\|", "\(", "\%(", "\n" 之后: 匹配行首;在其它位置	匹配 '^' 字符。 |/zero-width|	例如		匹配 ~	^beep(		C 函数 "beep" 开始的地方 (很可能).							*/\^*\^	匹配原字符 '^'。可以用于任何位置。							*/\_^*\_^	匹配行首。|/zero-width| 可以被用于任何位置。	例子		匹配 ~	\_s*\_^foo	空白字符及空行,后接行首的 "foo"。							*/$*$	在模式终点或 "\|", "\)" ("\v" 之后的 "|", ")" ) 之前: 匹配行尾 <EOL>;	其它位置,匹配原字符 '$'。|/zero-width|							*/\$*\$	匹配原字符 '$'。可以被用于任何位置。							*/\_$*\_$	匹配行尾。|/zero-width|  可以被用于任何位置。	例子		匹配 ~	foo\_$\_s*	"foo" 在行尾,后接空白字符及空行.	(with 'nomagic': \.)				*/.* */\.*	匹配任何单个字符,不包括行尾。							*/\_.*\_.	匹配任何单个字符,或行尾。当心:"\_.*" 会一直匹配到缓冲结尾!							*/\<*\<	匹配单词起点:下一个字符是单词的首字符。'iskeyword' 选项指定那些是	组成单词的字符。|/zero-width|							*/\>*\>	匹配单词终点:前一个字符是单词的尾字符。'iskeyword' 选项指定那些是	组成单词的字符。|/zero-width|							*/\zs*\zs	匹配任何位置,并将匹配起始处置于该处: 下一个字符将是整个匹配的第一个	字符。|/zero-width|	可以被多次使用,最后一个分支中的将被选中。	例如: "^\s*\zsif" 匹配行首的 "if",忽略所有空白字符。	{not in Vi} {not available when compiled without the +syntax feature}							*/\ze*\ze	匹配任何位置,并将匹配结尾处置于该处: 前一个字符将是整个匹配的最后一个	字符。|/zero-width|	可以被多次使用,最后一个分支中的将被选中。	例如: "end\ze\(if\|for\)" 匹配 "endif" 和 "endfor" 中的 "end"。

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -