annotate runtime/doc/usr_27.txt @ 8553:ed28f4f1d7cf

Added tag v7.4.1566 for changeset 96968d6bba3e17b4ccd057dcb5ac9860048fa828
author Christian Brabandt <cb@256bit.org>
date Tue, 15 Mar 2016 13:15:05 +0100
parents 359743c1f59a
children 9f48eab77d62
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5294
359743c1f59a release version 7.4
Bram Moolenaar <bram@vim.org>
parents: 5247
diff changeset
1 *usr_27.txt* For Vim version 7.4. Last change: 2010 Mar 28
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 VIM USER MANUAL - by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 Search commands and patterns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 In chapter 3 a few simple search patterns were mentioned |03.9|. Vim can do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 much more complex searches. This chapter explains the most often used ones.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 A detailed specification can be found here: |pattern|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 |27.1| Ignoring case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |27.2| Wrapping around the file end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |27.3| Offsets
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |27.4| Matching multiple times
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 |27.5| Alternatives
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 |27.6| Character ranges
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 |27.7| Character classes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 |27.8| Matching a line break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 |27.9| Examples
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 Next chapter: |usr_28.txt| Folding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 Previous chapter: |usr_26.txt| Repeating
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 *27.1* Ignoring case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 By default, Vim's searches are case sensitive. Therefore, "include",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 "INCLUDE", and "Include" are three different words and a search will match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 only one of them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 Now switch on the 'ignorecase' option: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 :set ignorecase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 Search for "include" again, and now it will match "Include", "INCLUDE" and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 "InClUDe". (Set the 'hlsearch' option to quickly see where a pattern
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 matches.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 You can switch this off again with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 :set noignorecase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
2152
b9e314fe473f Updated runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
43 But let's keep it set, and search for "INCLUDE". It will match exactly the
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 same text as "include" did. Now set the 'smartcase' option: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 :set ignorecase smartcase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 If you have a pattern with at least one uppercase character, the search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 becomes case sensitive. The idea is that you didn't have to type that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 uppercase character, so you must have done it because you wanted case to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 match. That's smart!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 With these two options set you find the following matches:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 pattern matches ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 word word, Word, WORD, WoRd, etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 Word Word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 WORD WORD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 WoRd WoRd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 CASE IN ONE PATTERN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 If you want to ignore case for one specific pattern, you can do this by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 prepending the "\c" string. Using "\C" will make the pattern to match case.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 This overrules the 'ignorecase' and 'smartcase' options, when "\c" or "\C" is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 used their value doesn't matter.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 pattern matches ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 \Cword word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 \CWord Word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 \cword word, Word, WORD, WoRd, etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 \cWord word, Word, WORD, WoRd, etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 A big advantage of using "\c" and "\C" is that it sticks with the pattern.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 Thus if you repeat a pattern from the search history, the same will happen, no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 matter if 'ignorecase' or 'smartcase' was changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 The use of "\" items in search patterns depends on the 'magic' option.
2207
b17bbfa96fa0 Add the settabvar() and gettabvar() functions.
Bram Moolenaar <bram@vim.org>
parents: 2154
diff changeset
80 In this chapter we will assume 'magic' is on, because that is the
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 standard and recommended setting. If you would change 'magic', many
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 search patterns would suddenly become invalid.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 If your search takes much longer than you expected, you can interrupt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 it with CTRL-C on Unix and CTRL-Break on MS-DOS and MS-Windows.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 *27.2* Wrapping around the file end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 By default, a forward search starts searching for the given string at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 current cursor location. It then proceeds to the end of the file. If it has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 not found the string by that time, it starts from the beginning and searches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 from the start of the file to the cursor location.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 Keep in mind that when repeating the "n" command to search for the next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 match, you eventually get back to the first match. If you don't notice this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 you keep searching forever! To give you a hint, Vim displays this message:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 search hit BOTTOM, continuing at TOP ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 If you use the "?" command, to search in the other direction, you get this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 message:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 search hit TOP, continuing at BOTTOM ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 Still, you don't know when you are back at the first match. One way to see
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 this is by switching on the 'ruler' option: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 :set ruler
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 Vim will display the cursor position in the lower righthand corner of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 window (in the status line if there is one). It looks like this:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 101,29 84% ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 The first number is the line number of the cursor. Remember the line number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 where you started, so that you can check if you passed this position again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 NOT WRAPPING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 To turn off search wrapping, use the following command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 :set nowrapscan
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 Now when the search hits the end of the file, an error message displays:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 E385: search hit BOTTOM without match for: forever ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 Thus you can find all matches by going to the start of the file with "gg" and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 keep searching until you see this message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 If you search in the other direction, using "?", you get:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 E384: search hit TOP without match for: forever ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 *27.3* Offsets
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 By default, the search command leaves the cursor positioned on the beginning
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 of the pattern. You can tell Vim to leave it some other place by specifying
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 an offset. For the forward search command "/", the offset is specified by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 appending a slash (/) and the offset: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 /default/2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 This command searches for the pattern "default" and then moves to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 beginning of the second line past the pattern. Using this command on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 paragraph above, Vim finds the word "default" in the first line. Then the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 cursor is moved two lines down and lands on "an offset".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 If the offset is a simple number, the cursor will be placed at the beginning
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 of the line that many lines from the match. The offset number can be positive
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 or negative. If it is positive, the cursor moves down that many lines; if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 negative, it moves up.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 CHARACTER OFFSETS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 The "e" offset indicates an offset from the end of the match. It moves the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 cursor onto the last character of the match. The command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 /const/e
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 puts the cursor on the "t" of "const".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 From that position, adding a number moves forward that many characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 This command moves to the character just after the match: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 /const/e+1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 A positive number moves the cursor to the right, a negative number moves it to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 the left. For example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 /const/e-1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 moves the cursor to the "s" of "const".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 If the offset begins with "b", the cursor moves to the beginning of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 pattern. That's not very useful, since leaving out the "b" does the same
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 thing. It does get useful when a number is added or subtracted. The cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 then goes forward or backward that many characters. For example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 /const/b+2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 Moves the cursor to the beginning of the match and then two characters to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 right. Thus it lands on the "n".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 REPEATING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 To repeat searching for the previously used search pattern, but with a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 different offset, leave out the pattern: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 /that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 //e
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 Is equal to: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 /that/e
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 To repeat with the same offset: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 /
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 "n" does the same thing. To repeat while removing a previously used offset: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 //
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 SEARCHING BACKWARDS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 The "?" command uses offsets in the same way, but you must use "?" to separate
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 the offset from the pattern, instead of "/": >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 ?const?e-2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 The "b" and "e" keep their meaning, they don't change direction with the use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 of "?".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 START POSITION
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 When starting a search, it normally starts at the cursor position. When you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 specify a line offset, this can cause trouble. For example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 /const/-2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 This finds the next word "const" and then moves two lines up. If you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 use "n" to search again, Vim could start at the current position and find the same
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 "const" match. Then using the offset again, you would be back where you started.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 You would be stuck!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 It could be worse: Suppose there is another match with "const" in the next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 line. Then repeating the forward search would find this match and move two
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 lines up. Thus you would actually move the cursor back!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 When you specify a character offset, Vim will compensate for this. Thus the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 search starts a few characters forward or backward, so that the same match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 isn't found again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 *27.4* Matching multiple times
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 The "*" item specifies that the item before it can match any number of times.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 Thus: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 /a*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 matches "a", "aa", "aaa", etc. But also "" (the empty string), because zero
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 times is included.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 The "*" only applies to the item directly before it. Thus "ab*" matches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 "a", "ab", "abb", "abbb", etc. To match a whole string multiple times, it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 must be grouped into one item. This is done by putting "\(" before it and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 "\)" after it. Thus this command: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 /\(ab\)*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 Matches: "ab", "abab", "ababab", etc. And also "".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 To avoid matching the empty string, use "\+". This makes the previous item
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 match one or more times. >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 /ab\+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 Matches "ab", "abb", "abbb", etc. It does not match "a" when no "b" follows.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 To match an optional item, use "\=". Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 /folders\=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 Matches "folder" and "folders".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 SPECIFIC COUNTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 To match a specific number of items use the form "\{n,m}". "n" and "m" are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 numbers. The item before it will be matched "n" to "m" times |inclusive|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 /ab\{3,5}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 matches "abbb", "abbbb" and "abbbbb".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 When "n" is omitted, it defaults to zero. When "m" is omitted it defaults
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 to infinity. When ",m" is omitted, it matches exactly "n" times.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 Examples:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 pattern match count ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 \{,4} 0, 1, 2, 3 or 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 \{3,} 3, 4, 5, etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 \{0,1} 0 or 1, same as \=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 \{0,} 0 or more, same as *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 \{1,} 1 or more, same as \+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 \{3} 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 MATCHING AS LITTLE AS POSSIBLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 The items so far match as many characters as they can find. To match as few
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 as possible, use "\{-n,m}". It works the same as "\{n,m}", except that the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 minimal amount possible is used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 For example, use: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 /ab\{-1,3}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 Will match "ab" in "abbb". Actually, it will never match more than one b,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 because there is no reason to match more. It requires something else to force
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 it to match more than the lower limit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 The same rules apply to removing "n" and "m". It's even possible to remove
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 11
diff changeset
307 both of the numbers, resulting in "\{-}". This matches the item before it
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 11
diff changeset
308 zero or more times, as few as possible. The item by itself always matches
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 11
diff changeset
309 zero times. It is useful when combined with something else. Example: >
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 /a.\{-}b
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 This matches "axb" in "axbxb". If this pattern would be used: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 /a.*b
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 It would try to match as many characters as possible with ".*", thus it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 matches "axbxb" as a whole.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 *27.5* Alternatives
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 The "or" operator in a pattern is "\|". Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 /foo\|bar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 This matches "foo" or "bar". More alternatives can be concatenated: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 /one\|two\|three
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 Matches "one", "two" and "three".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 To match multiple times, the whole thing must be placed in "\(" and "\)": >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 /\(foo\|bar\)\+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 This matches "foo", "foobar", "foofoo", "barfoobar", etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 Another example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 /end\(if\|while\|for\)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 This matches "endif", "endwhile" and "endfor".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 A related item is "\&". This requires that both alternatives match in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 same place. The resulting match uses the last alternative. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 /forever\&...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 This matches "for" in "forever". It will not match "fortuin", for example.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 *27.6* Character ranges
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 To match "a", "b" or "c" you could use "/a\|b\|c". When you want to match all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 letters from "a" to "z" this gets very long. There is a shorter method: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 /[a-z]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 The [] construct matches a single character. Inside you specify which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 characters to match. You can include a list of characters, like this: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 /[0123456789abcdef]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 This will match any of the characters included. For consecutive characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 you can specify the range. "0-3" stands for "0123". "w-z" stands for "wxyz".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 Thus the same command as above can be shortened to: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 /[0-9a-f]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 To match the "-" character itself make it the first or last one in the range.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 These special characters are accepted to make it easier to use them inside a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 [] range (they can actually be used anywhere in the search pattern):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 \e <Esc>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 \t <Tab>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 \r <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 \b <BS>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 There are a few more special cases for [] ranges, see |/[]| for the whole
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 story.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 COMPLEMENTED RANGE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 To avoid matching a specific character, use "^" at the start of the range.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 The [] item then matches everything but the characters included. Example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 /"[^"]*"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 <
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 " a double quote
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 [^"] any character that is not a double quote
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 * as many as possible
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 " a double quote again
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 This matches "foo" and "3!x", including the double quotes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 PREDEFINED RANGES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 A number of ranges are used very often. Vim provides a shortcut for these.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 For example: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 /\a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 Finds alphabetic characters. This is equal to using "/[a-zA-Z]". Here are a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 few more of these:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 item matches equivalent ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 \d digit [0-9]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 \D non-digit [^0-9]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 \x hex digit [0-9a-fA-F]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 \X non-hex digit [^0-9a-fA-F]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 \s white space [ ] (<Tab> and <Space>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 \S non-white characters [^ ] (not <Tab> and <Space>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 \l lowercase alpha [a-z]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 \L non-lowercase alpha [^a-z]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 \u uppercase alpha [A-Z]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 \U non-uppercase alpha [^A-Z]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 Using these predefined ranges works a lot faster than the character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 range it stands for.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 These items can not be used inside []. Thus "[\d\l]" does NOT work to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 match a digit or lowercase alpha. Use "\(\d\|\l\)" instead.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 See |/\s| for the whole list of these ranges.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 *27.7* Character classes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 The character range matches a fixed set of characters. A character class is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 similar, but with an essential difference: The set of characters can be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 redefined without changing the search pattern.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 For example, search for this pattern: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 /\f\+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 The "\f" items stands for file name characters. Thus this matches a sequence
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 of characters that can be a file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 Which characters can be part of a file name depends on the system you are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 using. On MS-Windows, the backslash is included, on Unix it is not. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 specified with the 'isfname' option. The default value for Unix is: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 :set isfname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 isfname=@,48-57,/,.,-,_,+,,,#,$,%,~,=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 For other systems the default value is different. Thus you can make a search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 pattern with "\f" to match a file name, and it will automatically adjust to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 the system you are using it on.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 Actually, Unix allows using just about any character in a file name,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 including white space. Including these characters in 'isfname' would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 be theoretically correct. But it would make it impossible to find the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 end of a file name in text. Thus the default value of 'isfname' is a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 compromise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 The character classes are:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 item matches option ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 \i identifier characters 'isident'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 \I like \i, excluding digits
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 \k keyword characters 'iskeyword'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 \K like \k, excluding digits
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 \p printable characters 'isprint'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 \P like \p, excluding digits
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 \f file name characters 'isfname'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 \F like \f, excluding digits
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 *27.8* Matching a line break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 Vim can find a pattern that includes a line break. You need to specify where
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 the line break happens, because all items mentioned so far don't match a line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 To check for a line break in a specific place, use the "\n" item: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 /the\nword
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 This will match at a line that ends in "the" and the next line starts with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 "word". To match "the word" as well, you need to match a space or a line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 break. The item to use for it is "\_s": >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 /the\_sword
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 To allow any amount of white space: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 /the\_s\+word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 This also matches when "the " is at the end of a line and " word" at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 start of the next one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 "\s" matches white space, "\_s" matches white space or a line break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 Similarly, "\a" matches an alphabetic character, and "\_a" matches an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 alphabetic character or a line break. The other character classes and ranges
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 can be modified in the same way by inserting a "_".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 Many other items can be made to match a line break by prepending "\_". For
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 example: "\_." matches any character or a line break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 "\_.*" matches everything until the end of the file. Be careful with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 this, it can make a search command very slow.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 Another example is "\_[]", a character range that includes a line break: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 /"\_[^"]*"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 This finds a text in double quotes that may be split up in several lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 *27.9* Examples
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 Here are a few search patterns you might find useful. This shows how the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 items mentioned above can be combined.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 FINDING A CALIFORNIA LICENSE PLATE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1269
diff changeset
519 A sample license plate number is "1MGU103". It has one digit, three uppercase
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 letters and three digits. Directly putting this into a search pattern: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 /\d\u\u\u\d\d\d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 Another way is to specify that there are three digits and letters with a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 count: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 /\d\u\{3}\d\{3}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 Using [] ranges instead: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 /[0-9][A-Z]\{3}[0-9]\{3}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 Which one of these you should use? Whichever one you can remember. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 simple way you can remember is much faster than the fancy way that you can't.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 If you can remember them all, then avoid the last one, because it's both more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 typing and slower to execute.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 FINDING AN IDENTIFIER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 In C programs (and many other computer languages) an identifier starts with a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 letter and further consists of letters and digits. Underscores can be used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 too. This can be found with: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 /\<\h\w*\>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 "\<" and "\>" are used to find only whole words. "\h" stands for "[A-Za-z_]"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 and "\w" for "[0-9A-Za-z_]".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 Note:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 "\<" and "\>" depend on the 'iskeyword' option. If it includes "-",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 for example, then "ident-" is not matched. In this situation use: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 /\w\@<!\h\w*\w\@!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 <
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 This checks if "\w" does not match before or after the identifier.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 See |/\@<!| and |/\@!|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 Next chapter: |usr_28.txt| Folding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 Copyright: see |manual-copyright| vim:tw=78:ts=8:ft=help:norl: