Mercurial > vim
comparison runtime/doc/pattern.txt @ 16553:0e473e9e70c2 v8.1.1280
patch 8.1.1280: remarks about functionality not in Vi clutters the help
commit https://github.com/vim/vim/commit/25c9c680ec4dfbb51f4ef21c3460a48d3c67ffc8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 5 18:13:34 2019 +0200
patch 8.1.1280: remarks about functionality not in Vi clutters the help
Problem: Remarks about functionality not in Vi clutters the help.
Solution: Move all info about what is new in Vim or already existed in Vi to
vi_diff.txt. Remove {not in Vi} remarks. (closes #4268) Add
"noet" to the help files modeline. Also include many other help
file improvements.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 05 May 2019 18:15:06 +0200 |
parents | 5e25171e0e75 |
children | c002c4899529 |
comparison
equal
deleted
inserted
replaced
16552:deb3d4f5be8b | 16553:0e473e9e70c2 |
---|---|
1 *pattern.txt* For Vim version 8.1. Last change: 2019 Feb 21 | 1 *pattern.txt* For Vim version 8.1. Last change: 2019 May 05 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
76 current line | 76 current line |
77 3. the non-blank word under the cursor | 77 3. the non-blank word under the cursor |
78 4. the first non-blank word after the cursor, | 78 4. the first non-blank word after the cursor, |
79 in the current line | 79 in the current line |
80 Only whole keywords are searched for, like with the | 80 Only whole keywords are searched for, like with the |
81 command "/\<keyword\>". |exclusive| {not in Vi} | 81 command "/\<keyword\>". |exclusive| |
82 'ignorecase' is used, 'smartcase' is not. | 82 'ignorecase' is used, 'smartcase' is not. |
83 | 83 |
84 *#* | 84 *#* |
85 # Same as "*", but search backward. The pound sign | 85 # Same as "*", but search backward. The pound sign |
86 (character 163) also works. If the "#" key works as | 86 (character 163) also works. If the "#" key works as |
87 backspace, try using "stty erase <BS>" before starting | 87 backspace, try using "stty erase <BS>" before starting |
88 Vim (<BS> is CTRL-H or a real backspace). {not in Vi} | 88 Vim (<BS> is CTRL-H or a real backspace). |
89 | 89 |
90 *gstar* | 90 *gstar* |
91 g* Like "*", but don't put "\<" and "\>" around the word. | 91 g* Like "*", but don't put "\<" and "\>" around the word. |
92 This makes the search also find matches that are not a | 92 This makes the search also find matches that are not a |
93 whole word. {not in Vi} | 93 whole word. |
94 | 94 |
95 *g#* | 95 *g#* |
96 g# Like "#", but don't put "\<" and "\>" around the word. | 96 g# Like "#", but don't put "\<" and "\>" around the word. |
97 This makes the search also find matches that are not a | 97 This makes the search also find matches that are not a |
98 whole word. {not in Vi} | 98 whole word. |
99 | 99 |
100 *gd* | 100 *gd* |
101 gd Goto local Declaration. When the cursor is on a local | 101 gd Goto local Declaration. When the cursor is on a local |
102 variable, this command will jump to its declaration. | 102 variable, this command will jump to its declaration. |
103 First Vim searches for the start of the current | 103 First Vim searches for the start of the current |
111 really check the syntax, it only searches for a match | 111 really check the syntax, it only searches for a match |
112 with the keyword. If included files also need to be | 112 with the keyword. If included files also need to be |
113 searched use the commands listed in |include-search|. | 113 searched use the commands listed in |include-search|. |
114 After this command |n| searches forward for the next | 114 After this command |n| searches forward for the next |
115 match (not backward). | 115 match (not backward). |
116 {not in Vi} | |
117 | 116 |
118 *gD* | 117 *gD* |
119 gD Goto global Declaration. When the cursor is on a | 118 gD Goto global Declaration. When the cursor is on a |
120 global variable that is defined in the file, this | 119 global variable that is defined in the file, this |
121 command will jump to its declaration. This works just | 120 command will jump to its declaration. This works just |
122 like "gd", except that the search for the keyword | 121 like "gd", except that the search for the keyword |
123 always starts in line 1. {not in Vi} | 122 always starts in line 1. |
124 | 123 |
125 *1gd* | 124 *1gd* |
126 1gd Like "gd", but ignore matches inside a {} block that | 125 1gd Like "gd", but ignore matches inside a {} block that |
127 ends before the cursor position. {not in Vi} | 126 ends before the cursor position. |
128 | 127 |
129 *1gD* | 128 *1gD* |
130 1gD Like "gD", but ignore matches inside a {} block that | 129 1gD Like "gD", but ignore matches inside a {} block that |
131 ends before the cursor position. {not in Vi} | 130 ends before the cursor position. |
132 | 131 |
133 *CTRL-C* | 132 *CTRL-C* |
134 CTRL-C Interrupt current (search) command. Use CTRL-Break on | 133 CTRL-C Interrupt current (search) command. Use CTRL-Break on |
135 MS-DOS |dos-CTRL-Break|. | 134 MS-DOS |dos-CTRL-Break|. |
136 In Normal mode, any pending command is aborted. | 135 In Normal mode, any pending command is aborted. |
169 error message |:s_flags|. | 168 error message |:s_flags|. |
170 | 169 |
171 *search-offset* *{offset}* | 170 *search-offset* *{offset}* |
172 These commands search for the specified pattern. With "/" and "?" an | 171 These commands search for the specified pattern. With "/" and "?" an |
173 additional offset may be given. There are two types of offsets: line offsets | 172 additional offset may be given. There are two types of offsets: line offsets |
174 and character offsets. {the character offsets are not in Vi} | 173 and character offsets. |
175 | 174 |
176 The offset gives the cursor position relative to the found match: | 175 The offset gives the cursor position relative to the found match: |
177 [num] [num] lines downwards, in column 1 | 176 [num] [num] lines downwards, in column 1 |
178 +[num] [num] lines downwards, in column 1 | 177 +[num] [num] lines downwards, in column 1 |
179 -[num] [num] lines upwards, in column 1 | 178 -[num] [num] lines upwards, in column 1 |
301 The WORD may contain any non-blanks (<Tab>s and/or <Space>s). | 300 The WORD may contain any non-blanks (<Tab>s and/or <Space>s). |
302 Note that if you type with ten fingers, the characters are easy to remember: | 301 Note that if you type with ten fingers, the characters are easy to remember: |
303 the "#" is under your left hand middle finger (search to the left and up) and | 302 the "#" is under your left hand middle finger (search to the left and up) and |
304 the "*" is under your right hand middle finger (search to the right and down). | 303 the "*" is under your right hand middle finger (search to the right and down). |
305 (this depends on your keyboard layout though). | 304 (this depends on your keyboard layout though). |
306 | |
307 *E956* | |
308 In very rare cases a regular expression is used recursively. This can happen | |
309 when executing a pattern takes a long time and when checking for messages on | |
310 channels a callback is invoked that also uses a pattern or an autocommand is | |
311 triggered. In most cases this should be fine, but if a pattern is in use when | |
312 it's used again it fails. Usually this means there is something wrong with | |
313 the pattern. | |
314 | 305 |
315 *E956* | 306 *E956* |
316 In very rare cases a regular expression is used recursively. This can happen | 307 In very rare cases a regular expression is used recursively. This can happen |
317 when executing a pattern takes a long time and when checking for messages on | 308 when executing a pattern takes a long time and when checking for messages on |
318 channels a callback is invoked that also uses a pattern or an autocommand is | 309 channels a callback is invoked that also uses a pattern or an autocommand is |
453 More explanation and examples below, follow the links. *E64* *E871* | 444 More explanation and examples below, follow the links. *E64* *E871* |
454 | 445 |
455 multi ~ | 446 multi ~ |
456 'magic' 'nomagic' matches of the preceding atom ~ | 447 'magic' 'nomagic' matches of the preceding atom ~ |
457 |/star| * \* 0 or more as many as possible | 448 |/star| * \* 0 or more as many as possible |
458 |/\+| \+ \+ 1 or more as many as possible (*) | 449 |/\+| \+ \+ 1 or more as many as possible |
459 |/\=| \= \= 0 or 1 as many as possible (*) | 450 |/\=| \= \= 0 or 1 as many as possible |
460 |/\?| \? \? 0 or 1 as many as possible (*) | 451 |/\?| \? \? 0 or 1 as many as possible |
461 | 452 |
462 |/\{| \{n,m} \{n,m} n to m as many as possible (*) | 453 |/\{| \{n,m} \{n,m} n to m as many as possible |
463 \{n} \{n} n exactly (*) | 454 \{n} \{n} n exactly |
464 \{n,} \{n,} at least n as many as possible (*) | 455 \{n,} \{n,} at least n as many as possible |
465 \{,m} \{,m} 0 to m as many as possible (*) | 456 \{,m} \{,m} 0 to m as many as possible |
466 \{} \{} 0 or more as many as possible (same as *) (*) | 457 \{} \{} 0 or more as many as possible (same as *) |
467 | 458 |
468 |/\{-| \{-n,m} \{-n,m} n to m as few as possible (*) | 459 |/\{-| \{-n,m} \{-n,m} n to m as few as possible |
469 \{-n} \{-n} n exactly (*) | 460 \{-n} \{-n} n exactly |
470 \{-n,} \{-n,} at least n as few as possible (*) | 461 \{-n,} \{-n,} at least n as few as possible |
471 \{-,m} \{-,m} 0 to m as few as possible (*) | 462 \{-,m} \{-,m} 0 to m as few as possible |
472 \{-} \{-} 0 or more as few as possible (*) | 463 \{-} \{-} 0 or more as few as possible |
473 | 464 |
474 *E59* | 465 *E59* |
475 |/\@>| \@> \@> 1, like matching a whole pattern (*) | 466 |/\@>| \@> \@> 1, like matching a whole pattern |
476 |/\@=| \@= \@= nothing, requires a match |/zero-width| (*) | 467 |/\@=| \@= \@= nothing, requires a match |/zero-width| |
477 |/\@!| \@! \@! nothing, requires NO match |/zero-width| (*) | 468 |/\@!| \@! \@! nothing, requires NO match |/zero-width| |
478 |/\@<=| \@<= \@<= nothing, requires a match behind |/zero-width| (*) | 469 |/\@<=| \@<= \@<= nothing, requires a match behind |/zero-width| |
479 |/\@<!| \@<! \@<! nothing, requires NO match behind |/zero-width| (*) | 470 |/\@<!| \@<! \@<! nothing, requires NO match behind |/zero-width| |
480 | |
481 (*) {not in Vi} | |
482 | 471 |
483 | 472 |
484 Overview of ordinary atoms. */ordinary-atom* | 473 Overview of ordinary atoms. */ordinary-atom* |
485 More explanation and examples below, follow the links. | 474 More explanation and examples below, follow the links. |
486 | 475 |
505 |/\%'m| \%'m \%'m mark m position |/zero-width| | 494 |/\%'m| \%'m \%'m mark m position |/zero-width| |
506 |/\%l| \%23l \%23l in line 23 |/zero-width| | 495 |/\%l| \%23l \%23l in line 23 |/zero-width| |
507 |/\%c| \%23c \%23c in column 23 |/zero-width| | 496 |/\%c| \%23c \%23c in column 23 |/zero-width| |
508 |/\%v| \%23v \%23v in virtual column 23 |/zero-width| | 497 |/\%v| \%23v \%23v in virtual column 23 |/zero-width| |
509 | 498 |
510 Character classes {not in Vi}: */character-classes* | 499 Character classes: */character-classes* |
511 magic nomagic matches ~ | 500 magic nomagic matches ~ |
512 |/\i| \i \i identifier character (see 'isident' option) | 501 |/\i| \i \i identifier character (see 'isident' option) |
513 |/\I| \I \I like "\i", but excluding digits | 502 |/\I| \I \I like "\i", but excluding digits |
514 |/\k| \k \k keyword character (see 'iskeyword' option) | 503 |/\k| \k \k keyword character (see 'iskeyword' option) |
515 |/\K| \K \K like "\k", but excluding digits | 504 |/\K| \K \K like "\k", but excluding digits |
544 |/\t| \t \t <Tab> | 533 |/\t| \t \t <Tab> |
545 |/\r| \r \r <CR> | 534 |/\r| \r \r <CR> |
546 |/\b| \b \b <BS> | 535 |/\b| \b \b <BS> |
547 |/\n| \n \n end-of-line | 536 |/\n| \n \n end-of-line |
548 |/~| ~ \~ last given substitute string | 537 |/~| ~ \~ last given substitute string |
549 |/\1| \1 \1 same string as matched by first \(\) {not in Vi} | 538 |/\1| \1 \1 same string as matched by first \(\) |
550 |/\2| \2 \2 Like "\1", but uses second \(\) | 539 |/\2| \2 \2 Like "\1", but uses second \(\) |
551 ... | 540 ... |
552 |/\9| \9 \9 Like "\1", but uses ninth \(\) | 541 |/\9| \9 \9 Like "\1", but uses ninth \(\) |
553 *E68* | 542 *E68* |
554 |/\z1| \z1 \z1 only for syntax highlighting, see |:syn-ext-match| | 543 |/\z1| \z1 \z1 only for syntax highlighting, see |:syn-ext-match| |
622 will match as many as possible, this first skips over all lines until | 611 will match as many as possible, this first skips over all lines until |
623 the end of the file and then tries matching "END", backing up one | 612 the end of the file and then tries matching "END", backing up one |
624 character at a time. | 613 character at a time. |
625 | 614 |
626 */\+* | 615 */\+* |
627 \+ Matches 1 or more of the preceding atom, as many as possible. {not in | 616 \+ Matches 1 or more of the preceding atom, as many as possible. |
628 Vi} | |
629 Example matches ~ | 617 Example matches ~ |
630 ^.\+$ any non-empty line | 618 ^.\+$ any non-empty line |
631 \s\+ white space of at least one character | 619 \s\+ white space of at least one character |
632 | 620 |
633 */\=* | 621 */\=* |
634 \= Matches 0 or 1 of the preceding atom, as many as possible. {not in Vi} | 622 \= Matches 0 or 1 of the preceding atom, as many as possible. |
635 Example matches ~ | 623 Example matches ~ |
636 foo\= "fo" and "foo" | 624 foo\= "fo" and "foo" |
637 | 625 |
638 */\?* | 626 */\?* |
639 \? Just like \=. Cannot be used when searching backwards with the "?" | 627 \? Just like \=. Cannot be used when searching backwards with the "?" |
640 command. {not in Vi} | 628 command. |
641 | 629 |
642 */\{* *E60* *E554* *E870* | 630 */\{* *E60* *E554* *E870* |
643 \{n,m} Matches n to m of the preceding atom, as many as possible | 631 \{n,m} Matches n to m of the preceding atom, as many as possible |
644 \{n} Matches n of the preceding atom | 632 \{n} Matches n of the preceding atom |
645 \{n,} Matches at least n of the preceding atom, as many as possible | 633 \{n,} Matches at least n of the preceding atom, as many as possible |
649 \{-n,m} matches n to m of the preceding atom, as few as possible | 637 \{-n,m} matches n to m of the preceding atom, as few as possible |
650 \{-n} matches n of the preceding atom | 638 \{-n} matches n of the preceding atom |
651 \{-n,} matches at least n of the preceding atom, as few as possible | 639 \{-n,} matches at least n of the preceding atom, as few as possible |
652 \{-,m} matches 0 to m of the preceding atom, as few as possible | 640 \{-,m} matches 0 to m of the preceding atom, as few as possible |
653 \{-} matches 0 or more of the preceding atom, as few as possible | 641 \{-} matches 0 or more of the preceding atom, as few as possible |
654 {Vi does not have any of these} | |
655 | 642 |
656 n and m are positive decimal numbers or zero | 643 n and m are positive decimal numbers or zero |
657 *non-greedy* | 644 *non-greedy* |
658 If a "-" appears immediately after the "{", then a shortest match | 645 If a "-" appears immediately after the "{", then a shortest match |
659 first algorithm is used (see example below). In particular, "\{-}" is | 646 first algorithm is used (see example below). In particular, "\{-}" is |
672 a[bc]*[cd] "abcd" in "abcd" | 659 a[bc]*[cd] "abcd" in "abcd" |
673 | 660 |
674 The } may optionally be preceded with a backslash: \{n,m\}. | 661 The } may optionally be preceded with a backslash: \{n,m\}. |
675 | 662 |
676 */\@=* | 663 */\@=* |
677 \@= Matches the preceding atom with zero width. {not in Vi} | 664 \@= Matches the preceding atom with zero width. |
678 Like "(?=pattern)" in Perl. | 665 Like "(?=pattern)" in Perl. |
679 Example matches ~ | 666 Example matches ~ |
680 foo\(bar\)\@= "foo" in "foobar" | 667 foo\(bar\)\@= "foo" in "foobar" |
681 foo\(bar\)\@=foo nothing | 668 foo\(bar\)\@=foo nothing |
682 */zero-width* | 669 */zero-width* |
692 braces. | 679 braces. |
693 | 680 |
694 | 681 |
695 */\@!* | 682 */\@!* |
696 \@! Matches with zero width if the preceding atom does NOT match at the | 683 \@! Matches with zero width if the preceding atom does NOT match at the |
697 current position. |/zero-width| {not in Vi} | 684 current position. |/zero-width| |
698 Like "(?!pattern)" in Perl. | 685 Like "(?!pattern)" in Perl. |
699 Example matches ~ | 686 Example matches ~ |
700 foo\(bar\)\@! any "foo" not followed by "bar" | 687 foo\(bar\)\@! any "foo" not followed by "bar" |
701 a.\{-}p\@! "a", "ap", "app", "appp", etc. not immediately | 688 a.\{-}p\@! "a", "ap", "app", "appp", etc. not immediately |
702 followed by a "p" | 689 followed by a "p" |
722 reject the pattern. When there is no match any "foo" will be found. | 709 reject the pattern. When there is no match any "foo" will be found. |
723 The "\zs" is to have the match start just before "foo". | 710 The "\zs" is to have the match start just before "foo". |
724 | 711 |
725 */\@<=* | 712 */\@<=* |
726 \@<= Matches with zero width if the preceding atom matches just before what | 713 \@<= Matches with zero width if the preceding atom matches just before what |
727 follows. |/zero-width| {not in Vi} | 714 follows. |/zero-width| |
728 Like "(?<=pattern)" in Perl, but Vim allows non-fixed-width patterns. | 715 Like "(?<=pattern)" in Perl, but Vim allows non-fixed-width patterns. |
729 Example matches ~ | 716 Example matches ~ |
730 \(an\_s\+\)\@<=file "file" after "an" and white space or an | 717 \(an\_s\+\)\@<=file "file" after "an" and white space or an |
731 end-of-line | 718 end-of-line |
732 For speed it's often much better to avoid this multi. Try using "\zs" | 719 For speed it's often much better to avoid this multi. Try using "\zs" |
766 | 753 |
767 */\@<!* | 754 */\@<!* |
768 \@<! Matches with zero width if the preceding atom does NOT match just | 755 \@<! Matches with zero width if the preceding atom does NOT match just |
769 before what follows. Thus this matches if there is no position in the | 756 before what follows. Thus this matches if there is no position in the |
770 current or previous line where the atom matches such that it ends just | 757 current or previous line where the atom matches such that it ends just |
771 before what follows. |/zero-width| {not in Vi} | 758 before what follows. |/zero-width| |
772 Like "(?<!pattern)" in Perl, but Vim allows non-fixed-width patterns. | 759 Like "(?<!pattern)" in Perl, but Vim allows non-fixed-width patterns. |
773 The match with the preceding atom is made to end just before the match | 760 The match with the preceding atom is made to end just before the match |
774 with what follows, thus an atom that ends in ".*" will work. | 761 with what follows, thus an atom that ends in ".*" will work. |
775 Warning: This can be slow (because many positions need to be checked | 762 Warning: This can be slow (because many positions need to be checked |
776 for a match). Use a limit if you can, see below. | 763 for a match). Use a limit if you can, see below. |
782 Like "\@<!" but only look back 123 bytes. This avoids trying lots of | 769 Like "\@<!" but only look back 123 bytes. This avoids trying lots of |
783 matches that are known to fail and make executing the pattern very | 770 matches that are known to fail and make executing the pattern very |
784 slow. | 771 slow. |
785 | 772 |
786 */\@>* | 773 */\@>* |
787 \@> Matches the preceding atom like matching a whole pattern. {not in Vi} | 774 \@> Matches the preceding atom like matching a whole pattern. |
788 Like "(?>pattern)" in Perl. | 775 Like "(?>pattern)" in Perl. |
789 Example matches ~ | 776 Example matches ~ |
790 \(a*\)\@>a nothing (the "a*" takes all the "a"'s, there can't be | 777 \(a*\)\@>a nothing (the "a*" takes all the "a"'s, there can't be |
791 another one following) | 778 another one following) |
792 | 779 |
861 Can be used multiple times, the last one encountered in a matching | 848 Can be used multiple times, the last one encountered in a matching |
862 branch is used. Example: > | 849 branch is used. Example: > |
863 /\(.\{-}\zsFab\)\{3} | 850 /\(.\{-}\zsFab\)\{3} |
864 < Finds the third occurrence of "Fab". | 851 < Finds the third occurrence of "Fab". |
865 This cannot be followed by a multi. *E888* | 852 This cannot be followed by a multi. *E888* |
866 {not in Vi} {not available when compiled without the |+syntax| feature} | 853 {not available when compiled without the |+syntax| feature} |
867 */\ze* | 854 */\ze* |
868 \ze Matches at any position, and sets the end of the match there: The | 855 \ze Matches at any position, and sets the end of the match there: The |
869 previous char is the last char of the whole match. |/zero-width| | 856 previous char is the last char of the whole match. |/zero-width| |
870 Can be used multiple times, the last one encountered in a matching | 857 Can be used multiple times, the last one encountered in a matching |
871 branch is used. | 858 branch is used. |
872 Example: "end\ze\(if\|for\)" matches the "end" in "endif" and | 859 Example: "end\ze\(if\|for\)" matches the "end" in "endif" and |
873 "endfor". | 860 "endfor". |
874 This cannot be followed by a multi. |E888| | 861 This cannot be followed by a multi. |E888| |
875 {not in Vi} {not available when compiled without the |+syntax| feature} | 862 {not available when compiled without the |+syntax| feature} |
876 | 863 |
877 */\%^* *start-of-file* | 864 */\%^* *start-of-file* |
878 \%^ Matches start of the file. When matching with a string, matches the | 865 \%^ Matches start of the file. When matching with a string, matches the |
879 start of the string. {not in Vi} | 866 start of the string. |
880 For example, to find the first "VIM" in a file: > | 867 For example, to find the first "VIM" in a file: > |
881 /\%^\_.\{-}\zsVIM | 868 /\%^\_.\{-}\zsVIM |
882 < | 869 < |
883 */\%$* *end-of-file* | 870 */\%$* *end-of-file* |
884 \%$ Matches end of the file. When matching with a string, matches the | 871 \%$ Matches end of the file. When matching with a string, matches the |
885 end of the string. {not in Vi} | 872 end of the string. |
886 Note that this does NOT find the last "VIM" in a file: > | 873 Note that this does NOT find the last "VIM" in a file: > |
887 /VIM\_.\{-}\%$ | 874 /VIM\_.\{-}\%$ |
888 < It will find the next VIM, because the part after it will always | 875 < It will find the next VIM, because the part after it will always |
889 match. This one will find the last "VIM" in the file: > | 876 match. This one will find the last "VIM" in the file: > |
890 /VIM\ze\(\(VIM\)\@!\_.\)*\%$ | 877 /VIM\ze\(\(VIM\)\@!\_.\)*\%$ |
904 < would match "foo bar" if the Visual selection continues after the "r". | 891 < would match "foo bar" if the Visual selection continues after the "r". |
905 Only works for the current buffer. | 892 Only works for the current buffer. |
906 | 893 |
907 */\%#* *cursor-position* | 894 */\%#* *cursor-position* |
908 \%# Matches with the cursor position. Only works when matching in a | 895 \%# Matches with the cursor position. Only works when matching in a |
909 buffer displayed in a window. {not in Vi} | 896 buffer displayed in a window. |
910 WARNING: When the cursor is moved after the pattern was used, the | 897 WARNING: When the cursor is moved after the pattern was used, the |
911 result becomes invalid. Vim doesn't automatically update the matches. | 898 result becomes invalid. Vim doesn't automatically update the matches. |
912 This is especially relevant for syntax highlighting and 'hlsearch'. | 899 This is especially relevant for syntax highlighting and 'hlsearch'. |
913 In other words: When the cursor moves the display isn't updated for | 900 In other words: When the cursor moves the display isn't updated for |
914 this change. An update is done for lines which are changed (the whole | 901 this change. An update is done for lines which are changed (the whole |
925 Example, to highlight the text from mark 's to 'e: > | 912 Example, to highlight the text from mark 's to 'e: > |
926 /.\%>'s.*\%<'e.. | 913 /.\%>'s.*\%<'e.. |
927 < Note that two dots are required to include mark 'e in the match. That | 914 < Note that two dots are required to include mark 'e in the match. That |
928 is because "\%<'e" matches at the character before the 'e mark, and | 915 is because "\%<'e" matches at the character before the 'e mark, and |
929 since it's a |/zero-width| match it doesn't include that character. | 916 since it's a |/zero-width| match it doesn't include that character. |
930 {not in Vi} | |
931 WARNING: When the mark is moved after the pattern was used, the result | 917 WARNING: When the mark is moved after the pattern was used, the result |
932 becomes invalid. Vim doesn't automatically update the matches. | 918 becomes invalid. Vim doesn't automatically update the matches. |
933 Similar to moving the cursor for "\%#" |/\%#|. | 919 Similar to moving the cursor for "\%#" |/\%#|. |
934 | 920 |
935 */\%l* */\%>l* */\%<l* *E951* | 921 */\%l* */\%>l* */\%<l* *E951* |
936 \%23l Matches in a specific line. | 922 \%23l Matches in a specific line. |
937 \%<23l Matches above a specific line (lower line number). | 923 \%<23l Matches above a specific line (lower line number). |
938 \%>23l Matches below a specific line (higher line number). | 924 \%>23l Matches below a specific line (higher line number). |
939 These three can be used to match specific lines in a buffer. The "23" | 925 These three can be used to match specific lines in a buffer. The "23" |
940 can be any line number. The first line is 1. {not in Vi} | 926 can be any line number. The first line is 1. |
941 WARNING: When inserting or deleting lines Vim does not automatically | 927 WARNING: When inserting or deleting lines Vim does not automatically |
942 update the matches. This means Syntax highlighting quickly becomes | 928 update the matches. This means Syntax highlighting quickly becomes |
943 wrong. | 929 wrong. |
944 Example, to highlight the line where the cursor currently is: > | 930 Example, to highlight the line where the cursor currently is: > |
945 :exe '/\%' . line(".") . 'l.*' | 931 :exe '/\%' . line(".") . 'l.*' |
951 \%<23c Matches before a specific column. | 937 \%<23c Matches before a specific column. |
952 \%>23c Matches after a specific column. | 938 \%>23c Matches after a specific column. |
953 These three can be used to match specific columns in a buffer or | 939 These three can be used to match specific columns in a buffer or |
954 string. The "23" can be any column number. The first column is 1. | 940 string. The "23" can be any column number. The first column is 1. |
955 Actually, the column is the byte number (thus it's not exactly right | 941 Actually, the column is the byte number (thus it's not exactly right |
956 for multi-byte characters). {not in Vi} | 942 for multi-byte characters). |
957 WARNING: When inserting or deleting text Vim does not automatically | 943 WARNING: When inserting or deleting text Vim does not automatically |
958 update the matches. This means Syntax highlighting quickly becomes | 944 update the matches. This means Syntax highlighting quickly becomes |
959 wrong. | 945 wrong. |
960 Example, to highlight the column where the cursor currently is: > | 946 Example, to highlight the column where the cursor currently is: > |
961 :exe '/\%' . col(".") . 'c' | 947 :exe '/\%' . col(".") . 'c' |
973 or string. When not matching with a buffer in a window, the option | 959 or string. When not matching with a buffer in a window, the option |
974 values of the current window are used (e.g., 'tabstop'). | 960 values of the current window are used (e.g., 'tabstop'). |
975 The "23" can be any column number. The first column is 1. | 961 The "23" can be any column number. The first column is 1. |
976 Note that some virtual column positions will never match, because they | 962 Note that some virtual column positions will never match, because they |
977 are halfway through a tab or other character that occupies more than | 963 are halfway through a tab or other character that occupies more than |
978 one screen character. {not in Vi} | 964 one screen character. |
979 WARNING: When inserting or deleting text Vim does not automatically | 965 WARNING: When inserting or deleting text Vim does not automatically |
980 update highlighted matches. This means Syntax highlighting quickly | 966 update highlighted matches. This means Syntax highlighting quickly |
981 becomes wrong. | 967 becomes wrong. |
982 Example, to highlight all the characters after virtual column 72: > | 968 Example, to highlight all the characters after virtual column 72: > |
983 /\%>72v.* | 969 /\%>72v.* |
996 /.*\%17v | 982 /.*\%17v |
997 < Column 17 is highlighted by 'hlsearch' because there is another match | 983 < Column 17 is highlighted by 'hlsearch' because there is another match |
998 where ".*" matches zero characters. | 984 where ".*" matches zero characters. |
999 < | 985 < |
1000 | 986 |
1001 Character classes: {not in Vi} | 987 Character classes: |
1002 \i identifier character (see 'isident' option) */\i* | 988 \i identifier character (see 'isident' option) */\i* |
1003 \I like "\i", but excluding digits */\I* | 989 \I like "\i", but excluding digits */\I* |
1004 \k keyword character (see 'iskeyword' option) */\k* | 990 \k keyword character (see 'iskeyword' option) */\k* |
1005 \K like "\k", but excluding digits */\K* | 991 \K like "\k", but excluding digits */\K* |
1006 \f file name character (see 'isfname' option) */\f* | 992 \f file name character (see 'isfname' option) */\f* |
1056 \(\) A pattern enclosed by escaped parentheses. */\(* */\(\)* */\)* | 1042 \(\) A pattern enclosed by escaped parentheses. */\(* */\(\)* */\)* |
1057 E.g., "\(^a\)" matches 'a' at the start of a line. | 1043 E.g., "\(^a\)" matches 'a' at the start of a line. |
1058 *E51* *E54* *E55* *E872* *E873* | 1044 *E51* *E54* *E55* *E872* *E873* |
1059 | 1045 |
1060 \1 Matches the same string that was matched by */\1* *E65* | 1046 \1 Matches the same string that was matched by */\1* *E65* |
1061 the first sub-expression in \( and \). {not in Vi} | 1047 the first sub-expression in \( and \). |
1062 Example: "\([a-z]\).\1" matches "ata", "ehe", "tot", etc. | 1048 Example: "\([a-z]\).\1" matches "ata", "ehe", "tot", etc. |
1063 \2 Like "\1", but uses second sub-expression, */\2* | 1049 \2 Like "\1", but uses second sub-expression, */\2* |
1064 ... */\3* | 1050 ... */\3* |
1065 \9 Like "\1", but uses ninth sub-expression. */\9* | 1051 \9 Like "\1", but uses ninth sub-expression. */\9* |
1066 Note: The numbering of groups is done based on which "\(" comes first | 1052 Note: The numbering of groups is done based on which "\(" comes first |
1068 first. | 1054 first. |
1069 | 1055 |
1070 \%(\) A pattern enclosed by escaped parentheses. */\%(\)* */\%(* *E53* | 1056 \%(\) A pattern enclosed by escaped parentheses. */\%(\)* */\%(* *E53* |
1071 Just like \(\), but without counting it as a sub-expression. This | 1057 Just like \(\), but without counting it as a sub-expression. This |
1072 allows using more groups and it's a little bit faster. | 1058 allows using more groups and it's a little bit faster. |
1073 {not in Vi} | |
1074 | 1059 |
1075 x A single character, with no special meaning, matches itself | 1060 x A single character, with no special meaning, matches itself |
1076 | 1061 |
1077 */\* */\\* | 1062 */\* */\\* |
1078 \x A backslash followed by a single character, with no special meaning, | 1063 \x A backslash followed by a single character, with no special meaning, |
1169 */\]* | 1154 */\]* |
1170 - To include a literal ']', '^', '-' or '\' in the collection, put a | 1155 - To include a literal ']', '^', '-' or '\' in the collection, put a |
1171 backslash before it: "[xyz\]]", "[\^xyz]", "[xy\-z]" and "[xyz\\]". | 1156 backslash before it: "[xyz\]]", "[\^xyz]", "[xy\-z]" and "[xyz\\]". |
1172 (Note: POSIX does not support the use of a backslash this way). For | 1157 (Note: POSIX does not support the use of a backslash this way). For |
1173 ']' you can also make it the first character (following a possible | 1158 ']' you can also make it the first character (following a possible |
1174 "^"): "[]xyz]" or "[^]xyz]" {not in Vi}. | 1159 "^"): "[]xyz]" or "[^]xyz]". |
1175 For '-' you can also make it the first or last character: "[-xyz]", | 1160 For '-' you can also make it the first or last character: "[-xyz]", |
1176 "[^-xyz]" or "[xyz-]". For '\' you can also let it be followed by | 1161 "[^-xyz]" or "[xyz-]". For '\' you can also let it be followed by |
1177 any character that's not in "^]-\bdertnoUux". "[\xyz]" matches '\', | 1162 any character that's not in "^]-\bdertnoUux". "[\xyz]" matches '\', |
1178 'x', 'y' and 'z'. It's better to use "\\" though, future expansions | 1163 'x', 'y' and 'z'. It's better to use "\\" though, future expansions |
1179 may use other characters after '\'. | 1164 may use other characters after '\'. |
1180 - Omitting the trailing ] is not considered an error. "[]" works like | 1165 - Omitting the trailing ] is not considered an error. "[]" works like |
1181 "[]]", it matches the ']' character. | 1166 "[]]", it matches the ']' character. |
1182 - The following translations are accepted when the 'l' flag is not | 1167 - The following translations are accepted when the 'l' flag is not |
1183 included in 'cpoptions' {not in Vi}: | 1168 included in 'cpoptions': |
1184 \e <Esc> | 1169 \e <Esc> |
1185 \t <Tab> | 1170 \t <Tab> |
1186 \r <CR> (NOT end-of-line!) | 1171 \r <CR> (NOT end-of-line!) |
1187 \b <BS> | 1172 \b <BS> |
1188 \n line break, see above |/[\n]| | 1173 \n line break, see above |/[\n]| |
1259 they are shown as "^@". The translation is done when reading and writing | 1244 they are shown as "^@". The translation is done when reading and writing |
1260 files. To match a <Nul> with a search pattern you can just enter CTRL-@ or | 1245 files. To match a <Nul> with a search pattern you can just enter CTRL-@ or |
1261 "CTRL-V 000". This is probably just what you expect. Internally the | 1246 "CTRL-V 000". This is probably just what you expect. Internally the |
1262 character is replaced with a <NL> in the search pattern. What is unusual is | 1247 character is replaced with a <NL> in the search pattern. What is unusual is |
1263 that typing CTRL-V CTRL-J also inserts a <NL>, thus also searches for a <Nul> | 1248 that typing CTRL-V CTRL-J also inserts a <NL>, thus also searches for a <Nul> |
1264 in the file. {Vi cannot handle <Nul> characters in the file at all} | 1249 in the file. |
1265 | 1250 |
1266 *CR-used-for-NL* | 1251 *CR-used-for-NL* |
1267 When 'fileformat' is "mac", <NL> characters in the file are stored as <CR> | 1252 When 'fileformat' is "mac", <NL> characters in the file are stored as <CR> |
1268 characters internally. In the text they are shown as "^J". Otherwise this | 1253 characters internally. In the text they are shown as "^J". Otherwise this |
1269 works similar to the usage of <NL> for a <Nul>. | 1254 works similar to the usage of <NL> for a <Nul>. |