323
|
1 *spell.txt* For Vim version 7.0aa. Last change: 2005 Jun 13
|
221
|
2
|
|
3
|
|
4 VIM REFERENCE MANUAL by Bram Moolenaar
|
|
5
|
|
6
|
|
7 Spell checking *spell*
|
|
8
|
|
9 1. Quick start |spell-quickstart|
|
237
|
10 2. Generating a spell file |spell-mkspell|
|
314
|
11 3. Spell file format |spell-file-format|
|
221
|
12
|
|
13 {Vi does not have any of these commands}
|
|
14
|
|
15 Spell checking is not available when the |+syntax| feature has been disabled
|
|
16 at compile time.
|
|
17
|
|
18 ==============================================================================
|
|
19 1. Quick start *spell-quickstart*
|
|
20
|
|
21 This command switches on spell checking: >
|
|
22
|
|
23 :setlocal spell spelllang=en_us
|
|
24
|
237
|
25 This switches on the 'spell' option and specifies to check for US English.
|
221
|
26
|
|
27 The words that are not recognized are highlighted with one of these:
|
|
28 SpellBad word not recognized
|
|
29 SpellRare rare word
|
|
30 SpellLocal wrong spelling for selected region
|
|
31
|
237
|
32 Vim only checks words for spelling, there is no grammar check.
|
|
33
|
|
34 To search for the next misspelled word:
|
|
35
|
|
36 *]s* *E756*
|
|
37 ]s Move to next misspelled word after the cursor.
|
253
|
38 A count before the command can be used to repeat.
|
|
39 This uses the @Spell and @NoSpell clusters from syntax
|
|
40 highlighting, see |spell-syntax|.
|
237
|
41
|
|
42 *[s*
|
253
|
43 [s Like "]s" but search backwards, find the misspelled
|
|
44 word before the cursor.
|
|
45
|
|
46 *]S*
|
|
47 ]S Like "]s" but only stop at bad words, not at rare
|
|
48 words or words for another region.
|
|
49
|
|
50 *[S*
|
|
51 [S Like "]S" but search backwards.
|
237
|
52
|
221
|
53
|
323
|
54 To add words to your own word list: *E764*
|
314
|
55
|
|
56 *zg*
|
|
57 zg Add word under the cursor as a good word to
|
|
58 'spellfile'. In Visual mode the selected characters
|
|
59 are added as a word (including white space!).
|
|
60
|
|
61 *zw*
|
|
62 zw Add word under the cursor as a wrong (bad) word to
|
|
63 'spellfile'. In Visual mode the selected characters
|
|
64 are added as a word (including white space!).
|
|
65
|
|
66 *:spellg* *:spellgood*
|
|
67 :spellg[ood] {word} Add [word} as a good word to 'spellfile'.
|
|
68
|
|
69 :spellw[rong] {word} Add [word} as a wrong (bad) word to 'spellfile'.
|
|
70
|
|
71 After adding a word to 'spellfile' its associated ".spl" file will
|
320
|
72 automatically be updated. More details about the 'spellfile' format below
|
|
73 |spell-wordlist-format|.
|
314
|
74
|
|
75
|
323
|
76 Finding suggestions for bad words:
|
|
77
|
|
78 *z?*
|
|
79 z? For the badly spelled word under the cursor suggest
|
|
80 the correctly spelled word.
|
|
81 When there is no badly spelled word under the cursor
|
|
82 use the one after the cursor, in the same line.
|
|
83 The results are sorted on similarity to the badly
|
|
84 spelled word.
|
|
85 This may take a long time. Hit CTRL-C when you are
|
|
86 bored.
|
|
87 You can enter the number of your choice or press
|
|
88 <Enter> if you don't want to replace.
|
|
89
|
|
90
|
227
|
91 PERFORMANCE
|
|
92
|
320
|
93 Note that Vim does on-the-fly spell checking. To make this work fast the
|
237
|
94 word list is loaded in memory. Thus this uses a lot of memory (1 Mbyte or
|
320
|
95 more). There might also be a noticeable delay when the word list is loaded,
|
|
96 which happens when 'spelllang' or 'spell' is set. Each word list is only
|
|
97 loaded once, they are not deleted when 'spelllang' is made empty or 'spell' is
|
|
98 reset. When 'encoding' is set the word lists are reloaded, thus you may
|
|
99 notice a delay then too.
|
227
|
100
|
|
101
|
221
|
102 REGIONS
|
|
103
|
|
104 A word may be spelled differently in various regions. For example, English
|
|
105 comes in (at least) these variants:
|
|
106
|
|
107 en all regions
|
247
|
108 en_au Australia
|
|
109 en_ca Canada
|
221
|
110 en_gb Great Britain
|
247
|
111 en_nz New Zealand
|
|
112 en_us USA
|
221
|
113
|
|
114 Words that are not used in one region but are used in another region are
|
320
|
115 highlighted with |SpellLocal|.
|
221
|
116
|
237
|
117 Always use lowercase letters for the language and region names.
|
221
|
118
|
320
|
119 When adding a word with |zg| or another command it's always added for all
|
|
120 regions. You can change that by manually editing the 'spellfile'. See
|
|
121 |spell-wordlist-format|.
|
|
122
|
221
|
123
|
|
124 SPELL FILES
|
|
125
|
|
126 Vim searches for spell files in the "spell" subdirectory of the directories in
|
320
|
127 'runtimepath'. The name is: LL.EEE.spl, where:
|
237
|
128 LL the language name
|
|
129 EEE the value of 'encoding'
|
221
|
130
|
320
|
131 Only the first file is loaded, the one that is first in 'runtimepath'. If
|
|
132 this succeeds then additionally files with the name LL.EEE.add.spl are loaded.
|
|
133 All the ones that are found are used.
|
|
134
|
242
|
135 Exceptions:
|
|
136 - Vim uses "latin1" when 'encoding' is "iso-8859-15". The euro sign doesn't
|
|
137 matter for spelling.
|
|
138 - When no spell file for 'encoding' is found "ascii" is tried. This only
|
|
139 works for languages where nearly all words are ASCII, such as English. It
|
|
140 helps when 'encoding' is not "latin1", such as iso-8859-2, and English text
|
320
|
141 is being edited. For the ".add" files the same name as the found main
|
|
142 spell file is used.
|
|
143
|
|
144 For example, with these values:
|
|
145 'runtimepath' is "~/.vim,/usr/share/vim70,~/.vim/after"
|
|
146 'encoding' is "iso-8859-2"
|
|
147 'spelllang' is "pl"
|
|
148
|
|
149 Vim will look for:
|
|
150 1. ~/.vim/spell/pl.iso-8859-2.spl
|
|
151 2. /usr/share/vim70/spell/pl.iso-8859-2.spl
|
|
152 3. ~/.vim/spell/pl.iso-8859-2.add.spl
|
|
153 4. /usr/share/vim70/spell/pl.iso-8859-2.add.spl
|
|
154 5. ~/.vim/after/spell/pl.iso-8859-2.add.spl
|
|
155
|
|
156 This assumes 1. is not found and 2. is found.
|
|
157
|
|
158 If 'encoding' is "latin1" Vim will look for:
|
|
159 1. ~/.vim/spell/pl.latin1.spl
|
|
160 2. /usr/share/vim70/spell/pl.latin1.spl
|
|
161 3. ~/.vim/after/spell/pl.latin1.spl
|
|
162 4. ~/.vim/spell/pl.ascii.spl
|
|
163 5. /usr/share/vim70/spell/pl.ascii.spl
|
|
164 6. ~/.vim/after/spell/pl.ascii.spl
|
|
165
|
|
166 This assumes none of them are found (Polish doesn't make sense when leaving
|
|
167 out the non-ASCII characters).
|
221
|
168
|
227
|
169 Spelling for EBCDIC is currently not supported.
|
|
170
|
237
|
171 A spell file might not be available in the current 'encoding'. See
|
|
172 |spell-mkspell| about how to create a spell file. Converting a spell file
|
242
|
173 with "iconv" will NOT work!
|
221
|
174
|
237
|
175 *E758* *E759*
|
|
176 When loading a spell file Vim checks that it is properly formatted. If you
|
242
|
177 get an error the file may be truncated, modified or intended for another Vim
|
|
178 version.
|
237
|
179
|
227
|
180
|
|
181 WORDS
|
|
182
|
|
183 Vim uses a fixed method to recognize a word. This is independent of
|
|
184 'iskeyword', so that it also works in help files and for languages that
|
|
185 include characters like '-' in 'iskeyword'. The word characters do depend on
|
|
186 'encoding'.
|
|
187
|
323
|
188 The table with word characters is stored in the main .spl file. Therefore it
|
|
189 matters what the current locale is when generating it! A .add.spl file does
|
|
190 not contain a word table.
|
|
191
|
320
|
192 A word that starts with a digit is always ignored. That includes hex numbers
|
|
193 in the form 0xff and 0XFF.
|
227
|
194
|
|
195
|
253
|
196 SYNTAX HIGHLIGHTING *spell-syntax*
|
227
|
197
|
|
198 Files that use syntax highlighting can specify where spell checking should be
|
|
199 done:
|
|
200
|
320
|
201 1. everywhere default
|
|
202 2. in specific items use "contains=@Spell"
|
|
203 3. everywhere but specific items use "contains=@NoSpell"
|
227
|
204
|
320
|
205 For the second method adding the @NoSpell cluster will disable spell checking
|
|
206 again. This can be used, for example, to add @Spell to the comments of a
|
|
207 program, and add @NoSpell for items that shouldn't be checked.
|
227
|
208
|
221
|
209 ==============================================================================
|
237
|
210 2. Generating a spell file *spell-mkspell*
|
|
211
|
|
212 Vim uses a binary file format for spelling. This greatly speeds up loading
|
|
213 the word list and keeps it small.
|
|
214
|
|
215 You can create a Vim spell file from the .aff and .dic files that Myspell
|
|
216 uses. Myspell is used by OpenOffice.org and Mozilla. You should be able to
|
|
217 find them here:
|
|
218 http://lingucomponent.openoffice.org/spell_dic.html
|
314
|
219 You can also use a plain word list.
|
221
|
220
|
242
|
221 :mksp[ell] [-ascii] {outname} {inname} ... *:mksp* *:mkspell*
|
314
|
222 Generate a Vim spell file word lists. Example: >
|
|
223 :mkspell nl nl_NL.words
|
|
224 <
|
|
225 When {outname} ends in ".spl" it is used as the output
|
|
226 file name. Otherwise it should be a language name,
|
|
227 such as "en". The file written will be
|
|
228 {outname}.{encoding}.spl. {encoding} is the value of
|
|
229 the 'encoding' option.
|
301
|
230
|
242
|
231 When the [-ascii] argument is present, words with
|
|
232 non-ascii characters are skipped. The resulting file
|
314
|
233 ends in "ascii.spl".
|
301
|
234
|
|
235 The input can be the Myspell format files {inname}.aff
|
|
236 and {inname}.dic. If {inname}.aff does not exist then
|
|
237 {inname} is used as the file name of a plain word
|
|
238 list.
|
|
239
|
237
|
240 Multiple {inname} arguments can be given to combine
|
|
241 regions into one Vim spell file. Example: >
|
|
242 :mkspell ~/.vim/spell/en /tmp/en_US /tmp/en_CA /tmp/en_AU
|
|
243 < This combines the English word lists for US, CA and AU
|
|
244 into one en.spl file.
|
|
245 Up to eight regions can be combined. *E754* *755*
|
323
|
246 The REP and SAL items of the first .aff file where
|
|
247 they appear are used. |spell-affix-REP|
|
|
248 |spell-affix-SAL|
|
237
|
249
|
308
|
250 When the spell file was written all currently used
|
|
251 spell files will be reloaded.
|
|
252
|
314
|
253 :mksp[ell] [-ascii] {add-name}
|
|
254 Like ":mkspell" above, using {add-name} as the input
|
|
255 file and producing an output file that has ".spl"
|
|
256 appended.
|
|
257
|
|
258 Since you might want to change a Myspell word list for use with Vim the
|
|
259 following procedure is recommended:
|
237
|
260
|
|
261 1. Obtain the xx_YY.aff and xx_YY.dic files from Myspell.
|
|
262 2. Make a copy of these files to xx_YY.orig.aff and xx_YY.orig.dic.
|
|
263 3. Change the xx_YY.aff and xx_YY.dic files to remove bad words, add missing
|
258
|
264 words, define word characters with FOL/LOW/UPP, etc. The distributed
|
|
265 "src/spell/*.diff" files can be used.
|
|
266 4. Set 'encoding' to the desired encoding and use |:mkspell| to generate the
|
|
267 Vim spell file.
|
|
268 5. Try out the spell file with ":set spell spelllang=xx_YY".
|
221
|
269
|
237
|
270 When the Myspell files are updated you can merge the differences:
|
258
|
271 1. Obtain the new Myspell files as xx_YY.new.aff and xx_UU.new.dic.
|
|
272 2. Use Vimdiff to see what changed: >
|
237
|
273 vimdiff xx_YY.orig.dic xx_YY.new.dic
|
258
|
274 3. Take over the changes you like in xx_YY.dic.
|
237
|
275 You may also need to change xx_YY.aff.
|
258
|
276 4. Rename xx_YY.new.dic to xx_YY.orig.dic and xx_YY.new.aff to xx_YY.new.aff.
|
237
|
277
|
|
278 ==============================================================================
|
|
279 9. Spell file format *spell-file-format*
|
|
280
|
|
281 This is the format of the files that are used by the person who creates and
|
|
282 maintains a word list.
|
221
|
283
|
237
|
284 Note that we avoid the word "dictionary" here. That is because the goal of
|
|
285 spell checking differs from writing a dictionary (as in the book). For
|
|
286 spelling we need a list of words that are OK, thus need not to be highlighted.
|
|
287 Names will not appear in a dictionary, but do appear in a word list. And
|
|
288 some old words are rarely used and are common misspellings. These do appear
|
|
289 in a dictionary but not in a word list.
|
|
290
|
301
|
291 There are two formats: one with affix compression and one without. The files
|
|
292 with affix compression are used by Myspell (Mozilla and OpenOffice.org). This
|
|
293 requires two files, one with .aff and one with .dic extension. The second
|
|
294 format is a list of words.
|
|
295
|
|
296
|
320
|
297 FORMAT OF WORD LIST *spell-wordlist-format*
|
301
|
298
|
314
|
299 The words must appear one per line. That is all that is required.
|
|
300 Additionally the following items are recognized:
|
301
|
301 - Empty and blank lines are ignored.
|
|
302 - Lines starting with a # are ignored (comment lines).
|
308
|
303 - A line starting with "/encoding=", before any word, specifies the encoding
|
|
304 of the file. After the second '=' comes an encoding name. This tells Vim
|
|
305 to setup conversion from the specified encoding to 'encoding'.
|
320
|
306 - A line starting with "/regions=" specifies the region names that are
|
|
307 supported. Each region name must be two ASCII letters. The first one is
|
|
308 region 1. Thus "/regions=usca" has region 1 "us" and region 2 "ca".
|
|
309 In an addition word list the list should be equal to the main word list!
|
308
|
310 - A line starting with "/?" specifies a word that should be marked as rare.
|
|
311 - A line starting with "/!" specifies a word that should be marked as bad.
|
|
312 - A line starting with "/=" specifies a word where case must match exactly.
|
|
313 A "?" or "!" may be following: "/=?" and "/=!".
|
320
|
314 - Digits after "/" indicate the regions in which the word is valid. If no
|
|
315 regions are specified the word is valid in all regions.
|
314
|
316 - Other lines starting with '/' are reserved for future use. The ones that
|
|
317 are not recognized are ignored (but you do get a warning message).
|
301
|
318
|
320
|
319 Example:
|
|
320
|
|
321 # This is an example word list comment
|
|
322 /encoding=latin1 encoding of the file
|
|
323 /regions=uscagb regions "us", "ca" and "gb"
|
|
324 example word for all regions
|
|
325 /1blah word for region 1 "us"
|
|
326 /!Vim bad word
|
|
327 /?3Campbell rare word in region 3 "gb"
|
|
328 /='s mornings keep-case word
|
|
329
|
301
|
330
|
|
331 FORMAT WITH AFFIX COMPRESSION
|
|
332
|
237
|
333 There are two files: the basic word list and an affix file. The affixes are
|
|
334 used to modify the basic words to get the full word list. This significantly
|
|
335 reduces the number of words, especially for a language like Polish. This is
|
|
336 called affix compression.
|
221
|
337
|
237
|
338 The format for the affix and word list files is mostly identical to what
|
|
339 Myspell uses (the spell checker of Mozilla and OpenOffice.org). A description
|
|
340 can be found here:
|
|
341 http://lingucomponent.openoffice.org/affix.readme ~
|
|
342 Note that affixes are case sensitive, this isn't obvious from the description.
|
314
|
343
|
237
|
344 Vim supports a few extras. Hopefully Myspell will support these too some day.
|
|
345 See |spell-affix-vim|.
|
|
346
|
|
347 The basic word list and the affix file are combined and turned into a binary
|
|
348 spell file. All the preprocessing has been done, thus this file loads fast.
|
|
349 The binary spell file format is described in the source code (src/spell.c).
|
|
350 But only developers need to know about it.
|
221
|
351
|
237
|
352 The preprocessing also allows us to take the Myspell language files and modify
|
|
353 them before the Vim word list is made. The tools for this can be found in the
|
|
354 "src/spell" directory.
|
|
355
|
|
356
|
320
|
357 WORD LIST FORMAT *spell-dic-format*
|
237
|
358
|
|
359 A very short example, with line numbers:
|
221
|
360
|
237
|
361 1 1234
|
|
362 2 aan
|
|
363 3 Als
|
|
364 4 Etten-Leur
|
|
365 5 et al.
|
|
366 6 's-Gravenhage
|
|
367 7 's-Gravenhaags
|
|
368 8 bedel/P
|
|
369 9 kado/1
|
|
370 10 cadeau/2
|
|
371
|
314
|
372 The first line contains the number of words. Vim ignores it, but you do get
|
|
373 an error message if it's not there. *E760*
|
221
|
374
|
314
|
375 What follows is one word per line. There should be no white space before or
|
|
376 after the word.
|
237
|
377
|
|
378 When the word only has lower-case letters it will also match with the word
|
|
379 starting with an upper-case letter.
|
|
380
|
|
381 When the word includes an upper-case letter, this means the upper-case letter
|
|
382 is required at this position. The same word with a lower-case letter at this
|
|
383 position will not match. When some of the other letters are upper-case it will
|
|
384 not match either.
|
|
385
|
|
386 The same word with all upper-case characters will always be OK.
|
221
|
387
|
237
|
388 word list matches does not match ~
|
|
389 als als Als ALS ALs AlS aLs aLS
|
|
390 Als Als ALS als ALs AlS aLs aLS
|
|
391 ALS ALS als Als ALs AlS aLs aLS
|
|
392 AlS AlS ALS als Als ALs aLs aLS
|
221
|
393
|
314
|
394 The KEP affix ID can be used to specifically match a word with identical case
|
308
|
395 only, see below.
|
|
396
|
237
|
397 Note in line 5 to 7 that non-word characters are used. You can include
|
|
398 any character in a word. When checking the text a word still only matches
|
|
399 when it appears with a non-word character before and after it. For Myspell a
|
|
400 word starting with a non-word character probably won't work.
|
|
401
|
|
402 After the word there is an optional slash and flags. Most of these flags are
|
|
403 letters that indicate the affixes that can be used with this word.
|
221
|
404
|
237
|
405 *spell-affix-vim*
|
314
|
406 A flag that Vim adds and is not in Myspell is the flag defined with KEP in the
|
308
|
407 affix file. This has the meaning that case matters. This can be used if the
|
|
408 word does not have the first letter in upper case at the start of a sentence.
|
314
|
409 Example (assuming that = was used for KEP):
|
237
|
410
|
|
411 word list matches does not match ~
|
|
412 's morgens/= 's morgens 'S morgens 's Morgens
|
|
413 's Morgens 's Morgens 'S morgens 's morgens
|
221
|
414
|
237
|
415 *spell-affix-mbyte*
|
|
416 The basic word list is normally in an 8-bit encoding, which is mentioned in
|
|
417 the affix file. The affix file must always be in the same encoding as the
|
|
418 word list. This is compatible with Myspell. For Vim the encoding may also be
|
|
419 something else, any encoding that "iconv" supports. The "SET" line must
|
|
420 specify the name of the encoding. When using a multi-byte encoding it's
|
|
421 possible to use more different affixes.
|
221
|
422
|
258
|
423 *spell-affix-chars*
|
314
|
424 When using an 8-bit encoding the affix file should define what characters are
|
|
425 word characters (as specified with ENC). This is because the system where
|
|
426 ":mkspell" is used may not support a locale with this encoding and isalpha()
|
|
427 won't work. For example when using "cp1250" on Unix.
|
258
|
428
|
|
429 *E761* *E762*
|
|
430 Three lines in the affix file are needed. Simplistic example:
|
|
431
|
308
|
432 FOL áëñáëñ ~
|
|
433 LOW áëñáëñ ~
|
|
434 UPP áëñÁËÑ ~
|
258
|
435
|
|
436 All three lines must have exactly the same number of characters.
|
|
437
|
|
438 The "FOL" line specifies the case-folded characters. These are used to
|
|
439 compare words while ignoring case. For most encodings this is identical to
|
|
440 the lower case line.
|
|
441
|
|
442 The "LOW" line specifies the characters in lower-case. Mostly it's equal to
|
|
443 the "FOL" line.
|
|
444
|
|
445 The "UPP" line specifies the characters with upper-case. That is, a character
|
|
446 is upper-case where it's different from the character at the same position in
|
|
447 "FOL".
|
|
448
|
|
449 ASCII characters should be omitted, Vim always handles these in the same way.
|
|
450 When the encoding is UTF-8 no word characters need to be specified.
|
|
451
|
|
452 *E763*
|
|
453 All spell files for the same encoding must use the same word characters,
|
264
|
454 otherwise they can't be combined without errors. The XX.ascii.spl spell file
|
|
455 generated with the "-ascii" argument will not contain the table with
|
|
456 characters, so that it can be combine with spell files for any encoding.
|
258
|
457
|
314
|
458 *spell-affix-KEP*
|
|
459 In the affix file a KEP line can be used to define the affix name used for
|
308
|
460 keep-case words. Example:
|
|
461
|
314
|
462 KEP = ~
|
308
|
463
|
|
464 See above for an example |spell-affix-vim|.
|
|
465
|
314
|
466 *spell-affix-RAR*
|
308
|
467 In the affix file a RAR line can be used to define the affix name used for
|
|
468 rare words. Example:
|
|
469
|
|
470 RAR ? ~
|
|
471
|
|
472 Rare words are highlighted differently from bad words. This is to be used for
|
|
473 words that are correct for the language, but are hardly ever used and could be
|
|
474 a typing mistake anyway.
|
|
475
|
|
476
|
323
|
477 REPLACEMENTS *spell-affix-REP*
|
|
478
|
|
479 In the affix file REP items can be used to define common mistakes. This is
|
|
480 used to make spelling suggestions. The items define the "from" text and the
|
|
481 "to" replacement. Example:
|
|
482
|
|
483 REP 4 ~
|
|
484 REP f ph ~
|
|
485 REP ph f ~
|
|
486 REP k ch ~
|
|
487 REP ch k ~
|
|
488
|
|
489 The first line specifies the number of REP lines following. Vim ignores it.
|
|
490
|
|
491
|
|
492 SIMILAR CHARACTERS *spell-affix-MAP*
|
|
493
|
|
494 In the affix file MAP items can be used to define letters that very much
|
|
495 alike. This is mostly used for a letter with different accents. This is used
|
|
496 to prefer suggestions with these letters substituted. Example:
|
|
497
|
|
498 MAP 2 ~
|
|
499 MAP eéëêè ~
|
|
500 MAP uüùúû ~
|
|
501
|
|
502 The first line specifies the number of MAP lines following. Vim ignores it.
|
|
503
|
|
504
|
|
505 SOUNDS-A-LIKE *spell-affix-SAL*
|
|
506
|
|
507 In the affix file SAL items can be used to define the sounds-a-like mechanism
|
|
508 to be used. The main items define the "from" text and the "to" replacement.
|
|
509 Example:
|
|
510
|
|
511 SAL CIA X ~
|
|
512 SAL CH X ~
|
|
513 SAL C K ~
|
|
514 SAL K K ~
|
|
515
|
|
516 TODO: explain how it works.
|
|
517
|
|
518 There are a few special items:
|
|
519
|
|
520 SAL followup true ~
|
|
521 SAL collapse_result true ~
|
|
522 SAL remove_accents true ~
|
|
523
|
|
524 "1" has the same meaning as "true". Any other value means "false".
|
|
525
|
221
|
526 vim:tw=78:sw=4:ts=8:ft=help:norl:
|