blob: 1a9e64f290f13dd6fc35e446605741cd9e0902e6 [file] [log] [blame]
Bram Moolenaard042c562005-06-30 22:04:15 +00001*spell.txt* For Vim version 7.0aa. Last change: 2005 Jun 30
Bram Moolenaar217ad922005-03-20 22:37:15 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Spell checking *spell*
8
91. Quick start |spell-quickstart|
Bram Moolenaard042c562005-06-30 22:04:15 +0000102. Remarks on spell checking |spell-remarks|
113. Generating a spell file |spell-mkspell|
124. Spell file format |spell-file-format|
Bram Moolenaar217ad922005-03-20 22:37:15 +000013
14{Vi does not have any of these commands}
15
16Spell checking is not available when the |+syntax| feature has been disabled
17at compile time.
18
19==============================================================================
201. Quick start *spell-quickstart*
21
22This command switches on spell checking: >
23
24 :setlocal spell spelllang=en_us
25
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000026This switches on the 'spell' option and specifies to check for US English.
Bram Moolenaar217ad922005-03-20 22:37:15 +000027
28The words that are not recognized are highlighted with one of these:
Bram Moolenaar520470a2005-06-16 21:59:56 +000029 SpellBad word not recognized |hl-SpellBad|
30 SpellRare rare word |hl-SpellRare|
31 SpellLocal wrong spelling for selected region |hl-SpellLocal|
Bram Moolenaar217ad922005-03-20 22:37:15 +000032
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000033Vim only checks words for spelling, there is no grammar check.
34
35To search for the next misspelled word:
36
37 *]s* *E756*
38]s Move to next misspelled word after the cursor.
Bram Moolenaar9d0ec2e2005-04-20 19:45:58 +000039 A count before the command can be used to repeat.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000040
41 *[s*
Bram Moolenaar9d0ec2e2005-04-20 19:45:58 +000042[s Like "]s" but search backwards, find the misspelled
Bram Moolenaar30abd282005-06-22 22:35:10 +000043 word before the cursor. Doesn't recognize words
44 split over two lines, thus may stop at words that are
45 not highlighted as bad.
Bram Moolenaar9d0ec2e2005-04-20 19:45:58 +000046
47 *]S*
48]S Like "]s" but only stop at bad words, not at rare
49 words or words for another region.
50
51 *[S*
52[S Like "]S" but search backwards.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000053
Bram Moolenaar217ad922005-03-20 22:37:15 +000054
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +000055To add words to your own word list: *E764*
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000056
57 *zg*
58zg Add word under the cursor as a good word to
59 'spellfile'. In Visual mode the selected characters
60 are added as a word (including white space!).
61
62 *zw*
63zw Add word under the cursor as a wrong (bad) word to
64 'spellfile'. In Visual mode the selected characters
65 are added as a word (including white space!).
66
Bram Moolenaar520470a2005-06-16 21:59:56 +000067 *:spe* *:spellgood*
68:spe[llgood] {word} Add [word} as a good word to 'spellfile'.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000069
Bram Moolenaar520470a2005-06-16 21:59:56 +000070 *:spellw* *:spellwrong*
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000071:spellw[rong] {word} Add [word} as a wrong (bad) word to 'spellfile'.
72
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000073After adding a word to 'spellfile' with the above commands its associated
Bram Moolenaard042c562005-06-30 22:04:15 +000074".spl" file will automatically be updated and reloaded. If you change
75'spellfile' manually you need to use the |:mkspell| command. This sequence of
76commands mostly works well: >
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000077 :exe 'e ' . &spellfile
78< (make changes to the spell file) >
79 :mkspell! %
80
81More details about the 'spellfile' format below |spell-wordlist-format|.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000082
83
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +000084Finding suggestions for bad words:
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +000085 *z?*
Bram Moolenaar30abd282005-06-22 22:35:10 +000086z? For the word under/after the cursor suggest correctly
Bram Moolenaard042c562005-06-30 22:04:15 +000087 spelled words. This also works to find alternatives
88 for a word that is not highlighted as a bad word,
89 e.g., when the word after it is bad.
Bram Moolenaar30abd282005-06-22 22:35:10 +000090 The results are sorted on similarity to the word
91 under/after the cursor.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +000092 This may take a long time. Hit CTRL-C when you are
93 bored.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000094 This does not work when there is a line break halfway
95 a bad word (e.g., "the the").
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +000096 You can enter the number of your choice or press
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000097 <Enter> if you don't want to replace. You can also
98 use the mouse to click on your choice (only works if
99 the mouse can be used in Normal mode and when there
Bram Moolenaard042c562005-06-30 22:04:15 +0000100 are no line wraps). Click on the first (header) line
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +0000101 to cancel.
Bram Moolenaarf3bd51a2005-06-14 22:11:18 +0000102 If 'verbose' is non-zero a score will be displayed to
103 indicate the likeliness to the badly spelled word (the
104 higher the score the more different).
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000105 When a word was replaced the redo command "." will
106 repeat the word replacement. This works like "ciw",
107 the good word and <Esc>.
108
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +0000109 *:spellr* *:spellrepall* *E752* *E753*
110:spellr[epall] Repeat the replacement done by |z?| for all matches
111 with the replaced word in the current window.
112
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000113The 'spellsuggest' option influences how the list of suggestions is generated
114and sorted. See |'spellsuggest'|.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000115
Bram Moolenaard042c562005-06-30 22:04:15 +0000116==============================================================================
1172. Remarks on spell checking *spell-remarks*
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000118
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000119PERFORMANCE
120
Bram Moolenaard042c562005-06-30 22:04:15 +0000121Vim does on-the-fly spell checking. To make this work fast the word list is
122loaded in memory. Thus this uses a lot of memory (1 Mbyte or more). There
123might also be a noticeable delay when the word list is loaded, which happens
124when 'spell' is set and when 'spelllang' is set while 'spell' was already set.
125To minimize the delay each word list is only loaded once, it is not deleted
126when 'spelllang' is made empty or 'spell' is reset. When 'encoding' is set
127all the word lists are reloaded, thus you may notice a delay then too.
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000128
129
Bram Moolenaar217ad922005-03-20 22:37:15 +0000130REGIONS
131
132A word may be spelled differently in various regions. For example, English
133comes in (at least) these variants:
134
135 en all regions
Bram Moolenaar5c5474b2005-04-19 21:40:26 +0000136 en_au Australia
Bram Moolenaar217ad922005-03-20 22:37:15 +0000137 en_ca Canada
Bram Moolenaar5c5474b2005-04-19 21:40:26 +0000138 en_gb Great Britain
139 en_nz New Zealand
140 en_us USA
Bram Moolenaar217ad922005-03-20 22:37:15 +0000141
142Words that are not used in one region but are used in another region are
Bram Moolenaar520470a2005-06-16 21:59:56 +0000143highlighted with SpellLocal |hl-SpellLocal|.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000144
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000145Always use lowercase letters for the language and region names.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000146
Bram Moolenaar3638c682005-06-08 22:05:14 +0000147When adding a word with |zg| or another command it's always added for all
148regions. You can change that by manually editing the 'spellfile'. See
149|spell-wordlist-format|.
150
Bram Moolenaar217ad922005-03-20 22:37:15 +0000151
Bram Moolenaar3b506942005-06-23 22:36:45 +0000152SPELL FILES *spell-load*
Bram Moolenaar217ad922005-03-20 22:37:15 +0000153
154Vim searches for spell files in the "spell" subdirectory of the directories in
Bram Moolenaar3638c682005-06-08 22:05:14 +0000155'runtimepath'. The name is: LL.EEE.spl, where:
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000156 LL the language name
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000157 EEE the value of 'encoding'
Bram Moolenaar217ad922005-03-20 22:37:15 +0000158
Bram Moolenaar3b506942005-06-23 22:36:45 +0000159The value for "LL" comes from 'spelllang', but excludes the region name.
160Examples:
161 'spelllang' LL ~
162 en_us en
163 en-rare en-rare
164 medical_ca medical
165
Bram Moolenaar3638c682005-06-08 22:05:14 +0000166Only the first file is loaded, the one that is first in 'runtimepath'. If
167this succeeds then additionally files with the name LL.EEE.add.spl are loaded.
168All the ones that are found are used.
169
Bram Moolenaar3b506942005-06-23 22:36:45 +0000170Additionally, the file related to 'spellfile' is loaded. This is the file
171that |zg| and |zw| add good and wrong words to.
172
Bram Moolenaar0e21a3f2005-04-17 20:28:32 +0000173Exceptions:
174- Vim uses "latin1" when 'encoding' is "iso-8859-15". The euro sign doesn't
175 matter for spelling.
176- When no spell file for 'encoding' is found "ascii" is tried. This only
177 works for languages where nearly all words are ASCII, such as English. It
178 helps when 'encoding' is not "latin1", such as iso-8859-2, and English text
Bram Moolenaar3638c682005-06-08 22:05:14 +0000179 is being edited. For the ".add" files the same name as the found main
180 spell file is used.
181
182For example, with these values:
183 'runtimepath' is "~/.vim,/usr/share/vim70,~/.vim/after"
184 'encoding' is "iso-8859-2"
185 'spelllang' is "pl"
186
187Vim will look for:
1881. ~/.vim/spell/pl.iso-8859-2.spl
1892. /usr/share/vim70/spell/pl.iso-8859-2.spl
1903. ~/.vim/spell/pl.iso-8859-2.add.spl
1914. /usr/share/vim70/spell/pl.iso-8859-2.add.spl
1925. ~/.vim/after/spell/pl.iso-8859-2.add.spl
193
194This assumes 1. is not found and 2. is found.
195
196If 'encoding' is "latin1" Vim will look for:
1971. ~/.vim/spell/pl.latin1.spl
1982. /usr/share/vim70/spell/pl.latin1.spl
1993. ~/.vim/after/spell/pl.latin1.spl
2004. ~/.vim/spell/pl.ascii.spl
2015. /usr/share/vim70/spell/pl.ascii.spl
2026. ~/.vim/after/spell/pl.ascii.spl
203
204This assumes none of them are found (Polish doesn't make sense when leaving
205out the non-ASCII characters).
Bram Moolenaar217ad922005-03-20 22:37:15 +0000206
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000207Spelling for EBCDIC is currently not supported.
208
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000209A spell file might not be available in the current 'encoding'. See
210|spell-mkspell| about how to create a spell file. Converting a spell file
Bram Moolenaar0e21a3f2005-04-17 20:28:32 +0000211with "iconv" will NOT work!
Bram Moolenaar217ad922005-03-20 22:37:15 +0000212
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000213 *E758* *E759*
214When loading a spell file Vim checks that it is properly formatted. If you
Bram Moolenaar0e21a3f2005-04-17 20:28:32 +0000215get an error the file may be truncated, modified or intended for another Vim
216version.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000217
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000218
219WORDS
220
221Vim uses a fixed method to recognize a word. This is independent of
222'iskeyword', so that it also works in help files and for languages that
223include characters like '-' in 'iskeyword'. The word characters do depend on
224'encoding'.
225
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000226The table with word characters is stored in the main .spl file. Therefore it
227matters what the current locale is when generating it! A .add.spl file does
Bram Moolenaarf461c8e2005-06-25 23:04:51 +0000228not contain a word table though.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000229
Bram Moolenaar3638c682005-06-08 22:05:14 +0000230A word that starts with a digit is always ignored. That includes hex numbers
231in the form 0xff and 0XFF.
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000232
233
Bram Moolenaar30abd282005-06-22 22:35:10 +0000234WORD COMBINATIONS
235
236It is possible to spell-check words that include a space. This is used to
237recognize words that are invalid when used by themselves, e.g. for "et al.".
238It can also be used to recognize "the the" and highlight it.
239
240The number of spaces is irrelevant. In most cases a line break may also
241appear. However, this makes it difficult to find out where to start checking
242for spelling mistakes. When you make a change to one line and only that line
243is redrawn Vim won't look in the previous line, thus when "et" is at the end
244of the previous line "al." will be flagged as an error. And when you type
245"the<CR>the" the highlighting doesn't appear until the first line is redrawn.
246Use |CTRL-L| to redraw right away. "[s" will also stop at a word combination
247with a line break.
248
249When encountering a line break Vim skips characters such as '*', '>' and '"',
250so that comments in C, shell and Vim code can be spell checked.
251
252
Bram Moolenaar9d0ec2e2005-04-20 19:45:58 +0000253SYNTAX HIGHLIGHTING *spell-syntax*
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000254
255Files that use syntax highlighting can specify where spell checking should be
256done:
257
Bram Moolenaar3638c682005-06-08 22:05:14 +00002581. everywhere default
2592. in specific items use "contains=@Spell"
2603. everywhere but specific items use "contains=@NoSpell"
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000261
Bram Moolenaar3638c682005-06-08 22:05:14 +0000262For the second method adding the @NoSpell cluster will disable spell checking
263again. This can be used, for example, to add @Spell to the comments of a
264program, and add @NoSpell for items that shouldn't be checked.
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000265
Bram Moolenaar30abd282005-06-22 22:35:10 +0000266
267VIM SCRIPTS
268
269If you want to write a Vim script that does something with spelling, you may
270find these functions useful:
271
272 spellbadword() find badly spelled word at the cursor
273 spellsuggest() get list of spelling suggestions
Bram Moolenaard042c562005-06-30 22:04:15 +0000274 soundfold() get the sound-a-like version of a word
Bram Moolenaar30abd282005-06-22 22:35:10 +0000275
Bram Moolenaar217ad922005-03-20 22:37:15 +0000276==============================================================================
Bram Moolenaard042c562005-06-30 22:04:15 +00002773. Generating a spell file *spell-mkspell*
Bram Moolenaar217ad922005-03-20 22:37:15 +0000278
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000279Vim uses a binary file format for spelling. This greatly speeds up loading
280the word list and keeps it small.
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000281 *.aff* *.dic* *Myspell*
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000282You can create a Vim spell file from the .aff and .dic files that Myspell
283uses. Myspell is used by OpenOffice.org and Mozilla. You should be able to
284find them here:
285 http://lingucomponent.openoffice.org/spell_dic.html
Bram Moolenaar30abd282005-06-22 22:35:10 +0000286You can also use a plain word list. The results are the same, the choice
Bram Moolenaard042c562005-06-30 22:04:15 +0000287depends on what word lists you can find.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000288
Bram Moolenaare13305e2005-06-19 22:54:15 +0000289Make sure your current locale is set properly, otherwise Vim doesn't know what
290characters are upper/lower case letters. If the locale isn't available (e.g.,
291when using an MS-Windows codepage on Unix) add tables to the .aff file
Bram Moolenaar3b506942005-06-23 22:36:45 +0000292|spell-affix-chars|. If the .aff file doesn't define a table then the word
293table of the currently active spelling is used. If spelling is not active
294then Vim will try to guess.
Bram Moolenaare13305e2005-06-19 22:54:15 +0000295
Bram Moolenaar3b506942005-06-23 22:36:45 +0000296 *:mksp* *:mkspell*
297:mksp[ell][!] [-ascii] {outname} {inname} ...
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000298 Generate a Vim spell file word lists. Example: >
Bram Moolenaard042c562005-06-30 22:04:15 +0000299 :mkspell /tmp/nl nl_NL.words
Bram Moolenaar3b506942005-06-23 22:36:45 +0000300< *E751*
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000301 When {outname} ends in ".spl" it is used as the output
302 file name. Otherwise it should be a language name,
Bram Moolenaar3b506942005-06-23 22:36:45 +0000303 such as "en", without the region name. The file
304 written will be "{outname}.{encoding}.spl", where
305 {encoding} is the value of the 'encoding' option.
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000306
Bram Moolenaard042c562005-06-30 22:04:15 +0000307 When the output file already exists [!] must be used
Bram Moolenaar520470a2005-06-16 21:59:56 +0000308 to overwrite it.
309
Bram Moolenaar0e21a3f2005-04-17 20:28:32 +0000310 When the [-ascii] argument is present, words with
311 non-ascii characters are skipped. The resulting file
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000312 ends in "ascii.spl".
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000313
314 The input can be the Myspell format files {inname}.aff
315 and {inname}.dic. If {inname}.aff does not exist then
316 {inname} is used as the file name of a plain word
317 list.
318
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000319 Multiple {inname} arguments can be given to combine
320 regions into one Vim spell file. Example: >
321 :mkspell ~/.vim/spell/en /tmp/en_US /tmp/en_CA /tmp/en_AU
322< This combines the English word lists for US, CA and AU
323 into one en.spl file.
324 Up to eight regions can be combined. *E754* *755*
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000325 The REP and SAL items of the first .aff file where
326 they appear are used. |spell-affix-REP|
327 |spell-affix-SAL|
Bram Moolenaar217ad922005-03-20 22:37:15 +0000328
Bram Moolenaar30abd282005-06-22 22:35:10 +0000329 This command uses a lot of memory, required to find
330 the optimal word tree (Polish requires a few hundred
331 Mbyte). The final result will be much smaller.
332
Bram Moolenaard042c562005-06-30 22:04:15 +0000333 After the spell file was written and it was being used
334 in a buffer it will be reloaded automatically.
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000335
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000336:mksp[ell] [-ascii] {name}.{enc}.add
337 Like ":mkspell" above, using {name}.{enc}.add as the
Bram Moolenaard042c562005-06-30 22:04:15 +0000338 input file and producing an output file in the same
339 directory that has ".spl" appended.
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000340
341:mksp[ell] [-ascii] {name}
342 Like ":mkspell" above, using {name} as the input file
Bram Moolenaard042c562005-06-30 22:04:15 +0000343 and producing an output file in the same directory
344 that has ".{enc}.spl" appended.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000345
346Since you might want to change a Myspell word list for use with Vim the
347following procedure is recommended:
Bram Moolenaar217ad922005-03-20 22:37:15 +0000348
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00003491. Obtain the xx_YY.aff and xx_YY.dic files from Myspell.
3502. Make a copy of these files to xx_YY.orig.aff and xx_YY.orig.dic.
3513. Change the xx_YY.aff and xx_YY.dic files to remove bad words, add missing
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000352 words, define word characters with FOL/LOW/UPP, etc. The distributed
353 "src/spell/*.diff" files can be used.
Bram Moolenaard042c562005-06-30 22:04:15 +00003544. Start Vim with the right locale and use |:mkspell| to generate the Vim
355 spell file.
3565. Try out the spell file with ":set spell spelllang=xx" if you wrote it in
357 a spell directory in 'runtimepath, or ":set spelllang=xx.enc.spl" if you
358 wrote it somewhere else.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000359
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000360When the Myspell files are updated you can merge the differences:
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00003611. Obtain the new Myspell files as xx_YY.new.aff and xx_UU.new.dic.
3622. Use Vimdiff to see what changed: >
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000363 vimdiff xx_YY.orig.dic xx_YY.new.dic
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00003643. Take over the changes you like in xx_YY.dic.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000365 You may also need to change xx_YY.aff.
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00003664. Rename xx_YY.new.dic to xx_YY.orig.dic and xx_YY.new.aff to xx_YY.new.aff.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000367
Bram Moolenaar3b506942005-06-23 22:36:45 +0000368
369SPELL FILE DUMP
370
371If for some reason you want to check what words are supported by the currently
372used spelling files, use this command:
373
374 *:spelldump* *:spelld*
375:spelld[ump] Open a new window and fill it with all currently valid
376 words.
Bram Moolenaard042c562005-06-30 22:04:15 +0000377 Note: For some languages the result may be enormous,
378 causing Vim to run out of memory.
Bram Moolenaar3b506942005-06-23 22:36:45 +0000379
380The format of the word list is used |spell-wordlist-format|. You should be
381able to read it with ":mkspell" to generate one .spl file that includes all
382the words.
383
384Only words for the current region are included. No "/regions" line is
385generated.
386
Bram Moolenaard042c562005-06-30 22:04:15 +0000387Comment lines with the name of the .spl file are used as a header above the
388words that were generated from that .spl file.
Bram Moolenaar3b506942005-06-23 22:36:45 +0000389
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000390==============================================================================
Bram Moolenaard042c562005-06-30 22:04:15 +00003914. Spell file format *spell-file-format*
Bram Moolenaar217ad922005-03-20 22:37:15 +0000392
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000393This is the format of the files that are used by the person who creates and
394maintains a word list.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000395
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000396Note that we avoid the word "dictionary" here. That is because the goal of
397spell checking differs from writing a dictionary (as in the book). For
Bram Moolenaard042c562005-06-30 22:04:15 +0000398spelling we need a list of words that are OK, thus should not to be
399highlighted. Person and company names will not appear in a dictionary, but do
400appear in a word list. And some old words are rarely used while they are
401common misspellings. These do appear in a dictionary but not in a word list.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000402
Bram Moolenaard042c562005-06-30 22:04:15 +0000403There are two formats: A straigth list of words and a list using affix
404compression. The files with affix compression are used by Myspell (Mozilla
405and OpenOffice.org). This requires two files, one with .aff and one with .dic
406extension.
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000407
408
Bram Moolenaard042c562005-06-30 22:04:15 +0000409FORMAT OF STRAIGHT WORD LIST *spell-wordlist-format*
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000410
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000411The words must appear one per line. That is all that is required.
Bram Moolenaard042c562005-06-30 22:04:15 +0000412
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000413Additionally the following items are recognized:
Bram Moolenaard042c562005-06-30 22:04:15 +0000414
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000415- Empty and blank lines are ignored.
Bram Moolenaard042c562005-06-30 22:04:15 +0000416
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000417- Lines starting with a # are ignored (comment lines).
Bram Moolenaard042c562005-06-30 22:04:15 +0000418
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000419- A line starting with "/encoding=", before any word, specifies the encoding
420 of the file. After the second '=' comes an encoding name. This tells Vim
Bram Moolenaard042c562005-06-30 22:04:15 +0000421 to setup conversion from the specified encoding to 'encoding'. Thus you can
422 use one word list for several target encodings.
423
Bram Moolenaar3638c682005-06-08 22:05:14 +0000424- A line starting with "/regions=" specifies the region names that are
425 supported. Each region name must be two ASCII letters. The first one is
426 region 1. Thus "/regions=usca" has region 1 "us" and region 2 "ca".
Bram Moolenaard042c562005-06-30 22:04:15 +0000427 In an addition word list the region names should be equal to the main word
428 list!
429
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000430- A line starting with "/?" specifies a word that should be marked as rare.
Bram Moolenaard042c562005-06-30 22:04:15 +0000431
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000432- A line starting with "/!" specifies a word that should be marked as bad.
Bram Moolenaard042c562005-06-30 22:04:15 +0000433
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000434- A line starting with "/=" specifies a word where case must match exactly.
435 A "?" or "!" may be following: "/=?" and "/=!".
Bram Moolenaard042c562005-06-30 22:04:15 +0000436
Bram Moolenaar3638c682005-06-08 22:05:14 +0000437- Digits after "/" indicate the regions in which the word is valid. If no
438 regions are specified the word is valid in all regions.
Bram Moolenaard042c562005-06-30 22:04:15 +0000439
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000440- Other lines starting with '/' are reserved for future use. The ones that
441 are not recognized are ignored (but you do get a warning message).
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000442
Bram Moolenaar3638c682005-06-08 22:05:14 +0000443Example:
444
445 # This is an example word list comment
446 /encoding=latin1 encoding of the file
447 /regions=uscagb regions "us", "ca" and "gb"
448 example word for all regions
449 /1blah word for region 1 "us"
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000450 /!vim bad word
Bram Moolenaar3638c682005-06-08 22:05:14 +0000451 /?3Campbell rare word in region 3 "gb"
452 /='s mornings keep-case word
453
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000454
455FORMAT WITH AFFIX COMPRESSION
456
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000457There are two files: the basic word list and an affix file. The affixes are
458used to modify the basic words to get the full word list. This significantly
459reduces the number of words, especially for a language like Polish. This is
460called affix compression.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000461
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000462The format for the affix and word list files is mostly identical to what
463Myspell uses (the spell checker of Mozilla and OpenOffice.org). A description
464can be found here:
465 http://lingucomponent.openoffice.org/affix.readme ~
466Note that affixes are case sensitive, this isn't obvious from the description.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000467
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000468Vim supports a few extras. Hopefully Myspell will support these too some day.
469See |spell-affix-vim|.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000470
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000471The basic word list and the affix file are combined and turned into a binary
472spell file. All the preprocessing has been done, thus this file loads fast.
473The binary spell file format is described in the source code (src/spell.c).
474But only developers need to know about it.
475
476The preprocessing also allows us to take the Myspell language files and modify
477them before the Vim word list is made. The tools for this can be found in the
478"src/spell" directory.
479
480
Bram Moolenaar3638c682005-06-08 22:05:14 +0000481WORD LIST FORMAT *spell-dic-format*
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000482
483A very short example, with line numbers:
484
485 1 1234
486 2 aan
487 3 Als
488 4 Etten-Leur
489 5 et al.
490 6 's-Gravenhage
491 7 's-Gravenhaags
492 8 bedel/P
493 9 kado/1
494 10 cadeau/2
495
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000496The first line contains the number of words. Vim ignores it, but you do get
497an error message if it's not there. *E760*
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000498
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000499What follows is one word per line. There should be no white space before or
500after the word.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000501
502When the word only has lower-case letters it will also match with the word
503starting with an upper-case letter.
504
505When the word includes an upper-case letter, this means the upper-case letter
506is required at this position. The same word with a lower-case letter at this
507position will not match. When some of the other letters are upper-case it will
508not match either.
509
Bram Moolenaard042c562005-06-30 22:04:15 +0000510The word with all upper-case characters will always be OK.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000511
512 word list matches does not match ~
513 als als Als ALS ALs AlS aLs aLS
514 Als Als ALS als ALs AlS aLs aLS
515 ALS ALS als Als ALs AlS aLs aLS
516 AlS AlS ALS als Als ALs aLs aLS
517
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000518The KEP affix ID can be used to specifically match a word with identical case
Bram Moolenaare7566042005-06-17 22:00:15 +0000519only, see below |spell-affix-KEP|.
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000520
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000521Note in line 5 to 7 that non-word characters are used. You can include
522any character in a word. When checking the text a word still only matches
523when it appears with a non-word character before and after it. For Myspell a
524word starting with a non-word character probably won't work.
525
526After the word there is an optional slash and flags. Most of these flags are
Bram Moolenaard042c562005-06-30 22:04:15 +0000527letters that indicate the affixes that can be used with this word. These are
528specified with SFX and PFX lines in the .aff file. See the Myspell
529documentation.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000530
531 *spell-affix-vim*
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000532A flag that Vim adds and is not in Myspell is the flag defined with KEP in the
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000533affix file. This has the meaning that case matters. This can be used if the
534word does not have the first letter in upper case at the start of a sentence.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000535Example (assuming that = was used for KEP):
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000536
537 word list matches does not match ~
538 's morgens/= 's morgens 'S morgens 's Morgens
539 's Morgens 's Morgens 'S morgens 's morgens
540
541 *spell-affix-mbyte*
542The basic word list is normally in an 8-bit encoding, which is mentioned in
543the affix file. The affix file must always be in the same encoding as the
544word list. This is compatible with Myspell. For Vim the encoding may also be
545something else, any encoding that "iconv" supports. The "SET" line must
546specify the name of the encoding. When using a multi-byte encoding it's
Bram Moolenaard042c562005-06-30 22:04:15 +0000547possible to use more different affixes (but Myspell doesn't support that, thus
548you may not want to use it anyway).
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000549
Bram Moolenaare13305e2005-06-19 22:54:15 +0000550
551CHARACTER TABLES
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000552 *spell-affix-chars*
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000553When using an 8-bit encoding the affix file should define what characters are
554word characters (as specified with ENC). This is because the system where
555":mkspell" is used may not support a locale with this encoding and isalpha()
556won't work. For example when using "cp1250" on Unix.
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000557
Bram Moolenaare7566042005-06-17 22:00:15 +0000558 *E761* *E762* *spell-affix-FOL*
559 *spell-affix-LOW* *spell-affix-UPP*
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000560Three lines in the affix file are needed. Simplistic example:
561
Bram Moolenaare13305e2005-06-19 22:54:15 +0000562 FOL áëñ ~
563 LOW áëñ ~
564 UPP ÁËÑ ~
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000565
566All three lines must have exactly the same number of characters.
567
568The "FOL" line specifies the case-folded characters. These are used to
569compare words while ignoring case. For most encodings this is identical to
570the lower case line.
571
572The "LOW" line specifies the characters in lower-case. Mostly it's equal to
573the "FOL" line.
574
575The "UPP" line specifies the characters with upper-case. That is, a character
576is upper-case where it's different from the character at the same position in
577"FOL".
578
579ASCII characters should be omitted, Vim always handles these in the same way.
580When the encoding is UTF-8 no word characters need to be specified.
581
582 *E763*
Bram Moolenaar3b506942005-06-23 22:36:45 +0000583Vim allows you to use spell checking for several languages in the same file.
584You can list them in the 'spelllang' option. As a consequence all spell files
585for the same encoding must use the same word characters, otherwise they can't
586be combined without errors. If you get a warning that the word tables differ
587you may need to generate the .spl file again with |:mkspell|. Check the FOL,
588LOW and UPP lines in the used .aff file.
589
590The XX.ascii.spl spell file generated with the "-ascii" argument will not
591contain the table with characters, so that it can be combine with spell files
592for any encoding. The .add.spl files also do not contain the table.
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000593
Bram Moolenaare7566042005-06-17 22:00:15 +0000594
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000595MID-WORD CHARACTERS
596 *spell-midword*
597Some characters are only to be considered word characters if they are used in
598between two ordinary word characters. An example is the single quote: It is
599often used to put text in quotes, thus it can't be recognized as a word
600character, but when it appears in between word characters it must be part of
601the word. This is needed to detect a spelling error such as they'are. That
602should be they're, but since "they" and "are" are words themselves that would
603go unnoticed.
604
605These characters are defined with MIDWORD in the .aff file:
606
607 MIDWORD '- ~
608
609
Bram Moolenaare13305e2005-06-19 22:54:15 +0000610AFFIXES
611 *spell-affix-PFX* *spell-affix-SFX*
612The usual PFX (prefix) and SFX (suffix) lines are supported (see the Myspell
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000613documentation or the Aspell manual:
614http://aspell.net/man-html/Affix-Compression.html).
Bram Moolenaare13305e2005-06-19 22:54:15 +0000615
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000616Note that Myspell ignores any extra text after the relevant info. Vim
617requires this text to start with a "#" so that mistakes don't go unnoticed.
618Example:
619
620 SFX F 0 in [^i]n # Spion > Spionin ~
621 SFX F 0 nen in # Bauerin > Bauerinnen ~
622
623An extra item for Vim is the "rare" flag. It must come after the other
624fields, before a comment. When used then all words that use the affix will be
625marked as rare words. Example:
626
627 PFX F 0 nene . rare ~
628 SFX F 0 oin n rare # hardly ever used ~
629
630However, if the word also appears as a good word in another way it won't be
631marked as rare.
Bram Moolenaare13305e2005-06-19 22:54:15 +0000632
633 *spell-affix-PFXPOSTPONE*
634When an affix file has very many prefixes that apply to many words it's not
635possible to build the whole word list in memory. This applies to Hebrew (a
636list with all words is over a Gbyte). In that case applying prefixes must be
637postponed. This makes spell checking slower. It is indicated by this keyword
638in the .aff file:
639
640 PFXPOSTPONE ~
641
642Only prefixes without a chop string can be postponed, prefixes with a chop
643string will still be included in the word list.
644
645
646KEEP-CASE WORDS
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000647 *spell-affix-KEP*
648In the affix file a KEP line can be used to define the affix name used for
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000649keep-case words. Example:
650
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000651 KEP = ~
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000652
653See above for an example |spell-affix-vim|.
654
Bram Moolenaare13305e2005-06-19 22:54:15 +0000655
656RARE WORDS
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000657 *spell-affix-RAR*
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000658In the affix file a RAR line can be used to define the affix name used for
659rare words. Example:
660
661 RAR ? ~
662
663Rare words are highlighted differently from bad words. This is to be used for
664words that are correct for the language, but are hardly ever used and could be
Bram Moolenaar30abd282005-06-22 22:35:10 +0000665a typing mistake anyway. When the same word is found as good it won't be
666highlighted as rare.
667
668
669BAD WORDS
670 *spell-affix-BAD*
671In the affix file a BAD line can be used to define the affix name used for
672bad words. Example:
673
674 BAD ! ~
675
676This can be used to exclude words that would otherwise be good. For example
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000677"the the" in the .dic file:
678
679 the the/! ~
680
681Once a word has been marked as bad it won't be undone by encountering the same
682word as good.
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000683
684
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000685REPLACEMENTS *spell-affix-REP*
686
687In the affix file REP items can be used to define common mistakes. This is
688used to make spelling suggestions. The items define the "from" text and the
689"to" replacement. Example:
690
691 REP 4 ~
692 REP f ph ~
693 REP ph f ~
694 REP k ch ~
695 REP ch k ~
696
697The first line specifies the number of REP lines following. Vim ignores it.
Bram Moolenaard042c562005-06-30 22:04:15 +0000698Don't include simple one-character replacements or swaps. Vim will try these
699anyway. You can include whole words if you want to, but you might want to use
700the "file:" item in 'spellsuggest' instead.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000701
702
703SIMILAR CHARACTERS *spell-affix-MAP*
704
Bram Moolenaard042c562005-06-30 22:04:15 +0000705In the affix file MAP items can be used to define letters that are very much
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000706alike. This is mostly used for a letter with different accents. This is used
707to prefer suggestions with these letters substituted. Example:
708
709 MAP 2 ~
710 MAP eéëêè ~
711 MAP uüùúû ~
712
713The first line specifies the number of MAP lines following. Vim ignores it.
714
Bram Moolenaard042c562005-06-30 22:04:15 +0000715Each letter must appear in only one of the MAP items. It's a bit more
716efficient if the first letter is ASCII or at least one without accents.
Bram Moolenaare7566042005-06-17 22:00:15 +0000717
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000718
Bram Moolenaard042c562005-06-30 22:04:15 +0000719SOUND-A-LIKE *spell-affix-SAL*
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000720
721In the affix file SAL items can be used to define the sounds-a-like mechanism
722to be used. The main items define the "from" text and the "to" replacement.
Bram Moolenaard042c562005-06-30 22:04:15 +0000723Simplistic example:
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000724
725 SAL CIA X ~
726 SAL CH X ~
727 SAL C K ~
728 SAL K K ~
729
Bram Moolenaard042c562005-06-30 22:04:15 +0000730There are a few rules and this can become quite complicated. An explantion
731how it works can be found in the Aspell manual:
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000732http://aspell.net/man-html/Phonetic-Code.html.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000733
734There are a few special items:
735
736 SAL followup true ~
737 SAL collapse_result true ~
738 SAL remove_accents true ~
739
740"1" has the same meaning as "true". Any other value means "false".
741
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000742
743SIMPLE SOUNDFOLDING *spell-affix-SOFOFROM* *spell-affix-SOFOTO*
744
745The SAL mechanism is complex and slow. A simpler mechanism is mapping all
746characters to another character, mapping similar sounding characters to the
747same character. At the same time this does case folding. You can not have
Bram Moolenaard042c562005-06-30 22:04:15 +0000748both SAL items and simple soundfolding.
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000749
750There are two items required: one to speficy the characters that are mapped
751and one that specifies the characters they are mapped to. They must have
752exactly the same number of characters. Example:
753
754 SOFOFROM abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ~
755 SOFOTO ebctefghejklnnepkrstevvkesebctefghejklnnepkrstevvkes ~
756
757In the example all vowels are mapped to the same character 'e'. Another
Bram Moolenaard042c562005-06-30 22:04:15 +0000758method would be to leave out all vowels. Some characters that sound nearly
759the same and are often mixed up, such as 'm' and 'n', are mapped to the same
760character. Don't do this too much, all words will start looking alike.
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000761
762Characters that do not appear in SOFOFROM will be left out, except that all
763white space is replaced by one space. Sequences of the same character in
764SOFOFROM are replaced by one.
765
766You can use the |soundfold()| function to try out the results. Or set the
767'verbose' option to see the score in the output of the |z?| command.
768
769
Bram Moolenaar217ad922005-03-20 22:37:15 +0000770 vim:tw=78:sw=4:ts=8:ft=help:norl: