📄 pattern.txt
字号:
*/bar* */\bar*1. A pattern is one or more branches, separated by "\|". It matches anything that matches one of the branches. Example: "foo\|beep" matches "foo" and "beep". If more than one branch matches, the first one is used.2. A branch is one or more pieces, concatenated. It matches a match for the first, followed by a match for the second, etc. Example: "foo[0-9]beep", first match "foo", then a digit and then "beep".3. A piece is an atom, possibly followed by: 'magic' 'nomagic' ~ */star* */\star* * \* matches 0 or more of the preceding atom, as much as possible (maximum 32767) */\+* \+ \+ matches 1 or more of the preceding atom, as much as possible (maximum 32767) {not in Vi} */\=* \= \= matches 0 or 1 of the preceding atom, as much as possible {not in Vi} */\{* \{n,m} \{n,m} matches n to m of the preceding atom, as much as possible {not in Vi} \{n} \{n} matches n of the preceding atom {not in Vi} \{n,} \{n,} matches at least n of the preceding atom, as much as possible {not in Vi} \{,m} \{,m} matches 0 to m of the preceding atom, as much as possible {not in Vi} \{} \{} matches 0 or more of the preceding atom, as much as possible (same as *) {not in Vi} */\{-* \{-n,m} \{-n,m} matches n to m of the preceding atom, as few as possible {not in Vi} \{-n} \{-n} matches n of the preceding atom {not in Vi} \{-n,} \{-n,} matches at least n of the preceding atom, as few as possible {not in Vi} \{-,m} \{-,m} matches 0 to m of the preceding atom, as few as possible {not in Vi} \{-} \{-} matches 0 or more of the preceding atom, as few as possible {not in Vi} (n and m are decimal numbers between 1 and 32767) If a "-" appears immediately after the "{", then a shortest match first algorithm is used (see example below). In particular, "\{-}" is the same as "*" but uses the shortest match first algorithm. BUT: A match that starts earlier is preferred over a shorter match: "a\{-}b" matches "aaab" in "xaaab". Examples: .* .\* matches anything, also empty string ^.\+$ ^.\+$ matches any non-empty line foo\= foo\= matches "fo" and "foo" ab\{2,3}c matches "abbc" or "abbbc" a\{5} matches "aaaaa". ab\{2,}c matches "abbc", "abbbc", "abbbbc", etc ab\{,3}c matches "ac", "abc", "abbc" or "abbbc". a[bc]\{3}d matches "abbbd", "abbcd", "acbcd", "acccd", etc. a\(bc\)\{1,2}d matches "abcd" or "abcbcd" a[bc]\{-}[cd] matches "abc" in "abcd" a[bc]*[cd] matches "abcd" in "abcd"4. An atom can be: magic nomagic ~ ^ ^ at beginning of pattern or after "\|" or */^* "\(", matches start of line; at other positions, matches literal '^' \^ \^ at any position, matches literal '^' */\^* $ $ at end of pattern or in front of "\|" or */$* "\)", matches end-of-line <EOL>; at other positions, matches literal '$' \$ \$ at any position, matches literal '$' */\$* . \. matches any single character */.* */\.* \< \< matches the beginning of a word */\<* \> \> matches the end of a word */\>* Character classes {not in Vi}: \i \i identifier character (see 'isident' option) */\i* \I \I like "\i", but excluding digits */\I* \k \k keyword character (see 'iskeyword' option) */\k* \K \K like "\k", but excluding digits */\K* \f \f file name character (see 'isfname' option) */\f* \F \F like "\f", but excluding digits */\F* \p \p printable character (see 'isprint' option) */\p* \P \P like "\p", but excluding digits */\P* *whitespace* *white-space* \s \s whitespace character: <Space> and <Tab> */\s* \S \S non-whitespace character; opposite of \s */\S* \d \d digit: [0-9] */\d* \D \D non-digit: [^0-9] */\D* \x \x hex digit: [0-9A-Fa-f] */\x* \X \X non-hex digit: [^0-9A-Fa-f] */\X* \o \o octal digit: [0-7] */\o* \O \O non-octal digit: [^0-7] */\O* \w \w word character: [0-9A-Za-z_] */\w* \W \W non-word character: [^0-9A-Za-z_] */\W* \h \h head of word character: [A-Za-z_] */\h* \H \H non-head of word character: [^A-Za-z_] */\H* \a \a alphabetic character: [A-Za-z] */\a* \A \A non-alphabetic character: [^A-Za-z] */\A* \l \l lowercase character: [a-z] */\l* \L \L non-lowercase character: [^a-z] */\L* \u \u uppercase character: [A-Z] */\u* \U \U non-uppercase character [^A-Z] */\U* NOTE: using the atom is faster than the [] form NOTE: 'ignorecase' is not used by character classes (end of character classes) \e \e matches <Esc> */\e* \t \t matches <Tab> */\t* \r \r matches <CR> */\r* \b \b matches <BS> */\b* \n \n matches <NL> Not available yet! Will be used */\n* for multi-line patterns ~ \~ matches the last given substitute string */~* */\~* \(\) \(\) A pattern enclosed by escaped parentheses */\(\)* (e.g., "\(^a\)") matches that pattern */\)* \1 \1 Matches the same string that was matched by */\1* the first sub-expression in \( and \). {not in Vi} Example: "\([a-z]\).\1" matches "ata", "ehe", "tot", etc. \2 \2 Like "\1", but uses second sub-expression, */\2* ... */\3* \9 \9 Like "\1", but uses ninth sub-expression. */\9* Note: The numbering of groups is done based on which "\(" comes first (going left to right). x x A single character, with no special meaning, matches itself \x \x A backslash followed by a single character, */\* */\\* with no special meaning, is reserved for future expansions [] \[] A range. This is a sequence of characters */[]* enclosed in "[]" or "\[]". It matches any */\[]* single character from the sequence. E.g., "[xyz]" matches any 'x', 'y' or 'z'. - If the sequence begins with "^", it matches any single character NOT in the sequence: "[^xyz]" matches anything but 'x', 'y' and 'z'. - If two characters in the sequence are separated by '-', this is shorthand for the full list of ASCII characters between them. E.g., "[0-9]" matches any decimal digit. - A character class expression is evaluated to the set of characters belonging to that character class. The following character classes are supported: Name Contents ~*[:alnum:]* [:alnum:] letters and digits*[:alpha:]* [:alpha:] letters*[:blank:]* [:blank:] space and tab characters*[:cntrl:]* [:cntrl:] control characters*[:digit:]* [:digit:] decimal digits*[:graph:]* [:graph:] printable characters excluding space*[:lower:]* [:lower:] lowercase letters*[:print:]* [:print:] printable characters including space*[:punct:]* [:punct:] punctuation characters*[:space:]* [:space:] whitespace characters*[:upper:]* [:upper:] uppercase letters*[:xdigit:]* [:xdigit:] hexadecimal digits*[:return:]* [:return:] the <CR> character*[:tab:]* [:tab:] the <Tab> character*[:escape:]* [:escape:] the <Esc> character*[:backspace:]* [:backspace:] the <BS> character The brackets in character class expressions are additional to the brackets delimiting a range. For example, the following is plausible for a UNIX filename: [-./[:alnum:]_~]\+ That is, a list of at least one character, each of which is either '-', '.', '/', alphabetic, numeric, '_' or '~'. */\]* - To include a literal ']', '^', '-' or '\' in the sequence, put a backslash before it: "[xyz\]]", "[\^xyz]", "[xy\-z]" and "[xyz\\]". (Note: POSIX does not support the use of a backslash this way). For ']' you can also make it the first character (following a possible "^"): "[]xyz]" or "[^]xyz]" {not in Vi}. For '-' you can also make it the first or last character: "[-xyz]", "[^-xyz]" or "[xyz-]". For '\' you can also let it be followed by any character that's not in "^]-\etrb". "[\xyz]" matches '\', 'x', 'y' and 'z'. It's better to use "\\" though, future expansions may use other characters after '\'. - The following translations are accepted when the 'l' flag is not included in 'cpoptions' {not in Vi}: \e <Esc> \t <Tab> \r <CR> \b <BS> NOTE: The other backslash codes mentioned above do not work inside []! - Matching ranges can be slow, use one of the other items above when possible.If the 'ignorecase' option is on, the case of letters is ignored. 'smartcase'can be set to ignore case when the pattern contains uppercase letters only.It is impossible to have a pattern that contains a line break (Sorry!).Examples:^beep( Probably the start of the C function "beep".[a-zA-Z]$ Any alphabetic character at the end of a line.\<\I\i* or\<\h\w*\<[a-zA-Z_][a-zA-Z0-9_]* An identifier (e.g., in a C program).\(\.$\|\. \) A period followed by <EOL> or a space.[.!?][])"']*\($\|[ ]\) A search pattern that finds the end of a sentence, with almost the same definition as the ")" command.Technical detail: *NL-used-for-Nul*<Nul> characters in the file are stored as <NL> in memory. In the displaythey are shown as "^@". The translation is done when reading and writingfiles. To match a <Nul> with a search pattern you can just enter CTRL-@ or"CTRL-V 000". This is probably just what you expect. Internally thecharacter is replaced with a <NL> in the search pattern. What is unusual isthat typing CTRL-V CTRL-J also inserts a <NL>, thus also searches for a <Nul>in the file. {Vi cannot handle <Nul> characters in the file at all} *CR-used-for-NL*When 'fileformat' is "mac", <NL> characters in the file are stored as <CR>characters internally. In the display they are shown as "^M". Otherwise thisworks similar to the usage of <NL> for a <Nul>. vim:tw=78:ts=8:sw=8:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -