blob: 9ccfbefb846c7938c4014089b4b75ebe0b0a5e41 [file] [log] [blame]
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00001*spell.txt* For Vim version 7.0aa. Last change: 2005 Jul 02
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|
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +000030 SpellCap word not capatilized |hl-SpellCap|
Bram Moolenaar520470a2005-06-16 21:59:56 +000031 SpellRare rare word |hl-SpellRare|
32 SpellLocal wrong spelling for selected region |hl-SpellLocal|
Bram Moolenaar217ad922005-03-20 22:37:15 +000033
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000034Vim only checks words for spelling, there is no grammar check.
35
36To search for the next misspelled word:
37
38 *]s* *E756*
39]s Move to next misspelled word after the cursor.
Bram Moolenaar9d0ec2e2005-04-20 19:45:58 +000040 A count before the command can be used to repeat.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000041
42 *[s*
Bram Moolenaar9d0ec2e2005-04-20 19:45:58 +000043[s Like "]s" but search backwards, find the misspelled
Bram Moolenaar30abd282005-06-22 22:35:10 +000044 word before the cursor. Doesn't recognize words
45 split over two lines, thus may stop at words that are
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +000046 not highlighted as bad. Does not stop at word with
47 missing capital at the start of a line.
Bram Moolenaar9d0ec2e2005-04-20 19:45:58 +000048
49 *]S*
50]S Like "]s" but only stop at bad words, not at rare
51 words or words for another region.
52
53 *[S*
54[S Like "]S" but search backwards.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000055
Bram Moolenaar217ad922005-03-20 22:37:15 +000056
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +000057To add words to your own word list: *E764*
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000058
59 *zg*
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +000060zg Add word under the cursor as a good word to the first
61 name in 'spellfile'. In Visual mode the selected
62 characters are added as a word (including white
63 space!). If the word is explicitly marked as bad word
64 in another spell file the result is unpredictable.
65 A count may precede the command to indicate the entry
66 in 'spellfile' to be used. A count of two uses the
67 second entry.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000068
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +000069 *zG*
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +000070zG Like "zg" but add the word to the internal word list
71 |internal-wordlist|.
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +000072
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000073 *zw*
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +000074zw Like "zg" but mark the word as a wrong (bad) word.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000075
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +000076 *zW*
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +000077zW Like "zw" but add the word to the internal word list
78 |internal-wordlist|.
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +000079
Bram Moolenaar520470a2005-06-16 21:59:56 +000080 *:spe* *:spellgood*
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +000081:[count]spe[llgood] {word}
82 Add [word} as a good word to 'spellfile', like with
83 "zg". Without count the first name is used, with a
84 count of two the second entry, etc.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000085
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +000086:spe[llgood]! {word} Add [word} as a good word to the internal word list,
87 like with "zG".
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +000088
Bram Moolenaar520470a2005-06-16 21:59:56 +000089 *:spellw* *:spellwrong*
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +000090:[count]spellw[rong] {word}
91 Add [word} as a wrong (bad) word to 'spellfile', as
92 with "zw". Without count the first name is used, with
93 a count of two the second entry, etc.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +000094
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +000095:spellw[rong]! {word} Add [word} as a wrong (bad) word to the internal word
96 list.
97
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000098After adding a word to 'spellfile' with the above commands its associated
Bram Moolenaard042c562005-06-30 22:04:15 +000099".spl" file will automatically be updated and reloaded. If you change
100'spellfile' manually you need to use the |:mkspell| command. This sequence of
101commands mostly works well: >
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000102 :edit <file in 'spellfile'>
Bram Moolenaarf461c8e2005-06-25 23:04:51 +0000103< (make changes to the spell file) >
104 :mkspell! %
105
106More details about the 'spellfile' format below |spell-wordlist-format|.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000107
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000108 *internal-wordlist*
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +0000109The internal word list is used for all buffers where 'spell' is set. It is
110not stored, it is lost when you exit Vim. It is also cleared when 'encoding'
111is set.
112
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000113
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000114Finding suggestions for bad words:
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000115 *z?*
Bram Moolenaar30abd282005-06-22 22:35:10 +0000116z? For the word under/after the cursor suggest correctly
Bram Moolenaard042c562005-06-30 22:04:15 +0000117 spelled words. This also works to find alternatives
118 for a word that is not highlighted as a bad word,
119 e.g., when the word after it is bad.
Bram Moolenaar30abd282005-06-22 22:35:10 +0000120 The results are sorted on similarity to the word
121 under/after the cursor.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000122 This may take a long time. Hit CTRL-C when you are
123 bored.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +0000124 This does not work when there is a line break halfway
125 a bad word (e.g., "the the").
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000126 You can enter the number of your choice or press
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +0000127 <Enter> if you don't want to replace. You can also
128 use the mouse to click on your choice (only works if
129 the mouse can be used in Normal mode and when there
Bram Moolenaard042c562005-06-30 22:04:15 +0000130 are no line wraps). Click on the first (header) line
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +0000131 to cancel.
Bram Moolenaarf3bd51a2005-06-14 22:11:18 +0000132 If 'verbose' is non-zero a score will be displayed to
133 indicate the likeliness to the badly spelled word (the
134 higher the score the more different).
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000135 When a word was replaced the redo command "." will
136 repeat the word replacement. This works like "ciw",
137 the good word and <Esc>.
138
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +0000139 *:spellr* *:spellrepall* *E752* *E753*
140:spellr[epall] Repeat the replacement done by |z?| for all matches
141 with the replaced word in the current window.
142
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000143The 'spellsuggest' option influences how the list of suggestions is generated
144and sorted. See |'spellsuggest'|.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000145
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000146The 'spellcapcheck' option is used to check the first word of a sentence
147starts with a capital. This doesn't work for the first word in the file.
148When there is a line break right after a sentence the highlighting of the next
149line may be postponed. Use |CTRL-L| when needed.
150
Bram Moolenaard042c562005-06-30 22:04:15 +0000151==============================================================================
1522. Remarks on spell checking *spell-remarks*
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000153
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000154PERFORMANCE
155
Bram Moolenaard042c562005-06-30 22:04:15 +0000156Vim does on-the-fly spell checking. To make this work fast the word list is
157loaded in memory. Thus this uses a lot of memory (1 Mbyte or more). There
158might also be a noticeable delay when the word list is loaded, which happens
159when 'spell' is set and when 'spelllang' is set while 'spell' was already set.
160To minimize the delay each word list is only loaded once, it is not deleted
161when 'spelllang' is made empty or 'spell' is reset. When 'encoding' is set
162all the word lists are reloaded, thus you may notice a delay then too.
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000163
164
Bram Moolenaar217ad922005-03-20 22:37:15 +0000165REGIONS
166
167A word may be spelled differently in various regions. For example, English
168comes in (at least) these variants:
169
170 en all regions
Bram Moolenaar5c5474b2005-04-19 21:40:26 +0000171 en_au Australia
Bram Moolenaar217ad922005-03-20 22:37:15 +0000172 en_ca Canada
Bram Moolenaar5c5474b2005-04-19 21:40:26 +0000173 en_gb Great Britain
174 en_nz New Zealand
175 en_us USA
Bram Moolenaar217ad922005-03-20 22:37:15 +0000176
177Words that are not used in one region but are used in another region are
Bram Moolenaar520470a2005-06-16 21:59:56 +0000178highlighted with SpellLocal |hl-SpellLocal|.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000179
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000180Always use lowercase letters for the language and region names.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000181
Bram Moolenaar3638c682005-06-08 22:05:14 +0000182When adding a word with |zg| or another command it's always added for all
183regions. You can change that by manually editing the 'spellfile'. See
184|spell-wordlist-format|.
185
Bram Moolenaar217ad922005-03-20 22:37:15 +0000186
Bram Moolenaar3b506942005-06-23 22:36:45 +0000187SPELL FILES *spell-load*
Bram Moolenaar217ad922005-03-20 22:37:15 +0000188
189Vim searches for spell files in the "spell" subdirectory of the directories in
Bram Moolenaar3638c682005-06-08 22:05:14 +0000190'runtimepath'. The name is: LL.EEE.spl, where:
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000191 LL the language name
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000192 EEE the value of 'encoding'
Bram Moolenaar217ad922005-03-20 22:37:15 +0000193
Bram Moolenaar3b506942005-06-23 22:36:45 +0000194The value for "LL" comes from 'spelllang', but excludes the region name.
195Examples:
196 'spelllang' LL ~
197 en_us en
198 en-rare en-rare
199 medical_ca medical
200
Bram Moolenaar3638c682005-06-08 22:05:14 +0000201Only the first file is loaded, the one that is first in 'runtimepath'. If
202this succeeds then additionally files with the name LL.EEE.add.spl are loaded.
203All the ones that are found are used.
204
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000205Additionally, the files related to the names in 'spellfile' are loaded. These
206are the files that |zg| and |zw| add good and wrong words to.
Bram Moolenaar3b506942005-06-23 22:36:45 +0000207
Bram Moolenaar0e21a3f2005-04-17 20:28:32 +0000208Exceptions:
209- Vim uses "latin1" when 'encoding' is "iso-8859-15". The euro sign doesn't
210 matter for spelling.
211- When no spell file for 'encoding' is found "ascii" is tried. This only
212 works for languages where nearly all words are ASCII, such as English. It
213 helps when 'encoding' is not "latin1", such as iso-8859-2, and English text
Bram Moolenaar3638c682005-06-08 22:05:14 +0000214 is being edited. For the ".add" files the same name as the found main
215 spell file is used.
216
217For example, with these values:
218 'runtimepath' is "~/.vim,/usr/share/vim70,~/.vim/after"
219 'encoding' is "iso-8859-2"
220 'spelllang' is "pl"
221
222Vim will look for:
2231. ~/.vim/spell/pl.iso-8859-2.spl
2242. /usr/share/vim70/spell/pl.iso-8859-2.spl
2253. ~/.vim/spell/pl.iso-8859-2.add.spl
2264. /usr/share/vim70/spell/pl.iso-8859-2.add.spl
2275. ~/.vim/after/spell/pl.iso-8859-2.add.spl
228
229This assumes 1. is not found and 2. is found.
230
231If 'encoding' is "latin1" Vim will look for:
2321. ~/.vim/spell/pl.latin1.spl
2332. /usr/share/vim70/spell/pl.latin1.spl
2343. ~/.vim/after/spell/pl.latin1.spl
2354. ~/.vim/spell/pl.ascii.spl
2365. /usr/share/vim70/spell/pl.ascii.spl
2376. ~/.vim/after/spell/pl.ascii.spl
238
239This assumes none of them are found (Polish doesn't make sense when leaving
240out the non-ASCII characters).
Bram Moolenaar217ad922005-03-20 22:37:15 +0000241
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000242Spelling for EBCDIC is currently not supported.
243
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000244A spell file might not be available in the current 'encoding'. See
245|spell-mkspell| about how to create a spell file. Converting a spell file
Bram Moolenaar0e21a3f2005-04-17 20:28:32 +0000246with "iconv" will NOT work!
Bram Moolenaar217ad922005-03-20 22:37:15 +0000247
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000248 *E758* *E759*
249When loading a spell file Vim checks that it is properly formatted. If you
Bram Moolenaar0e21a3f2005-04-17 20:28:32 +0000250get an error the file may be truncated, modified or intended for another Vim
251version.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000252
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000253
254WORDS
255
256Vim uses a fixed method to recognize a word. This is independent of
257'iskeyword', so that it also works in help files and for languages that
258include characters like '-' in 'iskeyword'. The word characters do depend on
259'encoding'.
260
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000261The table with word characters is stored in the main .spl file. Therefore it
262matters what the current locale is when generating it! A .add.spl file does
Bram Moolenaarf461c8e2005-06-25 23:04:51 +0000263not contain a word table though.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000264
Bram Moolenaar3638c682005-06-08 22:05:14 +0000265A word that starts with a digit is always ignored. That includes hex numbers
266in the form 0xff and 0XFF.
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000267
268
Bram Moolenaar30abd282005-06-22 22:35:10 +0000269WORD COMBINATIONS
270
271It is possible to spell-check words that include a space. This is used to
272recognize words that are invalid when used by themselves, e.g. for "et al.".
273It can also be used to recognize "the the" and highlight it.
274
275The number of spaces is irrelevant. In most cases a line break may also
276appear. However, this makes it difficult to find out where to start checking
277for spelling mistakes. When you make a change to one line and only that line
278is redrawn Vim won't look in the previous line, thus when "et" is at the end
279of the previous line "al." will be flagged as an error. And when you type
280"the<CR>the" the highlighting doesn't appear until the first line is redrawn.
281Use |CTRL-L| to redraw right away. "[s" will also stop at a word combination
282with a line break.
283
284When encountering a line break Vim skips characters such as '*', '>' and '"',
285so that comments in C, shell and Vim code can be spell checked.
286
287
Bram Moolenaar9d0ec2e2005-04-20 19:45:58 +0000288SYNTAX HIGHLIGHTING *spell-syntax*
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000289
290Files that use syntax highlighting can specify where spell checking should be
291done:
292
Bram Moolenaar3638c682005-06-08 22:05:14 +00002931. everywhere default
2942. in specific items use "contains=@Spell"
2953. everywhere but specific items use "contains=@NoSpell"
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000296
Bram Moolenaar3638c682005-06-08 22:05:14 +0000297For the second method adding the @NoSpell cluster will disable spell checking
298again. This can be used, for example, to add @Spell to the comments of a
299program, and add @NoSpell for items that shouldn't be checked.
Bram Moolenaar6bb68362005-03-22 23:03:44 +0000300
Bram Moolenaar30abd282005-06-22 22:35:10 +0000301
302VIM SCRIPTS
303
304If you want to write a Vim script that does something with spelling, you may
305find these functions useful:
306
307 spellbadword() find badly spelled word at the cursor
308 spellsuggest() get list of spelling suggestions
Bram Moolenaard042c562005-06-30 22:04:15 +0000309 soundfold() get the sound-a-like version of a word
Bram Moolenaar30abd282005-06-22 22:35:10 +0000310
Bram Moolenaar217ad922005-03-20 22:37:15 +0000311==============================================================================
Bram Moolenaard042c562005-06-30 22:04:15 +00003123. Generating a spell file *spell-mkspell*
Bram Moolenaar217ad922005-03-20 22:37:15 +0000313
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000314Vim uses a binary file format for spelling. This greatly speeds up loading
315the word list and keeps it small.
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000316 *.aff* *.dic* *Myspell*
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000317You can create a Vim spell file from the .aff and .dic files that Myspell
318uses. Myspell is used by OpenOffice.org and Mozilla. You should be able to
319find them here:
320 http://lingucomponent.openoffice.org/spell_dic.html
Bram Moolenaar30abd282005-06-22 22:35:10 +0000321You can also use a plain word list. The results are the same, the choice
Bram Moolenaard042c562005-06-30 22:04:15 +0000322depends on what word lists you can find.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000323
Bram Moolenaare13305e2005-06-19 22:54:15 +0000324Make sure your current locale is set properly, otherwise Vim doesn't know what
325characters are upper/lower case letters. If the locale isn't available (e.g.,
326when using an MS-Windows codepage on Unix) add tables to the .aff file
Bram Moolenaar3b506942005-06-23 22:36:45 +0000327|spell-affix-chars|. If the .aff file doesn't define a table then the word
328table of the currently active spelling is used. If spelling is not active
329then Vim will try to guess.
Bram Moolenaare13305e2005-06-19 22:54:15 +0000330
Bram Moolenaar3b506942005-06-23 22:36:45 +0000331 *:mksp* *:mkspell*
332:mksp[ell][!] [-ascii] {outname} {inname} ...
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000333 Generate a Vim spell file word lists. Example: >
Bram Moolenaard042c562005-06-30 22:04:15 +0000334 :mkspell /tmp/nl nl_NL.words
Bram Moolenaar3b506942005-06-23 22:36:45 +0000335< *E751*
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000336 When {outname} ends in ".spl" it is used as the output
337 file name. Otherwise it should be a language name,
Bram Moolenaar3b506942005-06-23 22:36:45 +0000338 such as "en", without the region name. The file
339 written will be "{outname}.{encoding}.spl", where
340 {encoding} is the value of the 'encoding' option.
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000341
Bram Moolenaard042c562005-06-30 22:04:15 +0000342 When the output file already exists [!] must be used
Bram Moolenaar520470a2005-06-16 21:59:56 +0000343 to overwrite it.
344
Bram Moolenaar0e21a3f2005-04-17 20:28:32 +0000345 When the [-ascii] argument is present, words with
346 non-ascii characters are skipped. The resulting file
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000347 ends in "ascii.spl".
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000348
349 The input can be the Myspell format files {inname}.aff
350 and {inname}.dic. If {inname}.aff does not exist then
351 {inname} is used as the file name of a plain word
352 list.
353
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000354 Multiple {inname} arguments can be given to combine
355 regions into one Vim spell file. Example: >
356 :mkspell ~/.vim/spell/en /tmp/en_US /tmp/en_CA /tmp/en_AU
357< This combines the English word lists for US, CA and AU
358 into one en.spl file.
359 Up to eight regions can be combined. *E754* *755*
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000360 The REP and SAL items of the first .aff file where
361 they appear are used. |spell-affix-REP|
362 |spell-affix-SAL|
Bram Moolenaar217ad922005-03-20 22:37:15 +0000363
Bram Moolenaar30abd282005-06-22 22:35:10 +0000364 This command uses a lot of memory, required to find
365 the optimal word tree (Polish requires a few hundred
366 Mbyte). The final result will be much smaller.
367
Bram Moolenaard042c562005-06-30 22:04:15 +0000368 After the spell file was written and it was being used
369 in a buffer it will be reloaded automatically.
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000370
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000371:mksp[ell] [-ascii] {name}.{enc}.add
372 Like ":mkspell" above, using {name}.{enc}.add as the
Bram Moolenaard042c562005-06-30 22:04:15 +0000373 input file and producing an output file in the same
374 directory that has ".spl" appended.
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000375
376:mksp[ell] [-ascii] {name}
377 Like ":mkspell" above, using {name} as the input file
Bram Moolenaard042c562005-06-30 22:04:15 +0000378 and producing an output file in the same directory
379 that has ".{enc}.spl" appended.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000380
381Since you might want to change a Myspell word list for use with Vim the
382following procedure is recommended:
Bram Moolenaar217ad922005-03-20 22:37:15 +0000383
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00003841. Obtain the xx_YY.aff and xx_YY.dic files from Myspell.
3852. Make a copy of these files to xx_YY.orig.aff and xx_YY.orig.dic.
3863. Change the xx_YY.aff and xx_YY.dic files to remove bad words, add missing
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000387 words, define word characters with FOL/LOW/UPP, etc. The distributed
388 "src/spell/*.diff" files can be used.
Bram Moolenaard042c562005-06-30 22:04:15 +00003894. Start Vim with the right locale and use |:mkspell| to generate the Vim
390 spell file.
3915. Try out the spell file with ":set spell spelllang=xx" if you wrote it in
392 a spell directory in 'runtimepath, or ":set spelllang=xx.enc.spl" if you
393 wrote it somewhere else.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000394
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000395When the Myspell files are updated you can merge the differences:
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00003961. Obtain the new Myspell files as xx_YY.new.aff and xx_UU.new.dic.
3972. Use Vimdiff to see what changed: >
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000398 vimdiff xx_YY.orig.dic xx_YY.new.dic
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00003993. Take over the changes you like in xx_YY.dic.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000400 You may also need to change xx_YY.aff.
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00004014. 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 +0000402
Bram Moolenaar3b506942005-06-23 22:36:45 +0000403
404SPELL FILE DUMP
405
406If for some reason you want to check what words are supported by the currently
407used spelling files, use this command:
408
409 *:spelldump* *:spelld*
410:spelld[ump] Open a new window and fill it with all currently valid
411 words.
Bram Moolenaard042c562005-06-30 22:04:15 +0000412 Note: For some languages the result may be enormous,
413 causing Vim to run out of memory.
Bram Moolenaar3b506942005-06-23 22:36:45 +0000414
415The format of the word list is used |spell-wordlist-format|. You should be
416able to read it with ":mkspell" to generate one .spl file that includes all
417the words.
418
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +0000419When all entries to 'spelllang' use the same regions or no regions at all then
420the region information is included in the dumped words. Otherwise only words
421for the current region are included and no "/regions" line is generated.
Bram Moolenaar3b506942005-06-23 22:36:45 +0000422
Bram Moolenaard042c562005-06-30 22:04:15 +0000423Comment lines with the name of the .spl file are used as a header above the
424words that were generated from that .spl file.
Bram Moolenaar3b506942005-06-23 22:36:45 +0000425
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000426==============================================================================
Bram Moolenaard042c562005-06-30 22:04:15 +00004274. Spell file format *spell-file-format*
Bram Moolenaar217ad922005-03-20 22:37:15 +0000428
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000429This is the format of the files that are used by the person who creates and
430maintains a word list.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000431
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000432Note that we avoid the word "dictionary" here. That is because the goal of
433spell checking differs from writing a dictionary (as in the book). For
Bram Moolenaard042c562005-06-30 22:04:15 +0000434spelling we need a list of words that are OK, thus should not to be
435highlighted. Person and company names will not appear in a dictionary, but do
436appear in a word list. And some old words are rarely used while they are
437common misspellings. These do appear in a dictionary but not in a word list.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000438
Bram Moolenaard042c562005-06-30 22:04:15 +0000439There are two formats: A straigth list of words and a list using affix
440compression. The files with affix compression are used by Myspell (Mozilla
441and OpenOffice.org). This requires two files, one with .aff and one with .dic
442extension.
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000443
444
Bram Moolenaard042c562005-06-30 22:04:15 +0000445FORMAT OF STRAIGHT WORD LIST *spell-wordlist-format*
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000446
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000447The words must appear one per line. That is all that is required.
Bram Moolenaard042c562005-06-30 22:04:15 +0000448
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000449Additionally the following items are recognized:
Bram Moolenaard042c562005-06-30 22:04:15 +0000450
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000451- Empty and blank lines are ignored.
Bram Moolenaard042c562005-06-30 22:04:15 +0000452
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000453- Lines starting with a # are ignored (comment lines).
Bram Moolenaard042c562005-06-30 22:04:15 +0000454
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000455- A line starting with "/encoding=", before any word, specifies the encoding
456 of the file. After the second '=' comes an encoding name. This tells Vim
Bram Moolenaard042c562005-06-30 22:04:15 +0000457 to setup conversion from the specified encoding to 'encoding'. Thus you can
458 use one word list for several target encodings.
459
Bram Moolenaar3638c682005-06-08 22:05:14 +0000460- A line starting with "/regions=" specifies the region names that are
461 supported. Each region name must be two ASCII letters. The first one is
462 region 1. Thus "/regions=usca" has region 1 "us" and region 2 "ca".
Bram Moolenaard042c562005-06-30 22:04:15 +0000463 In an addition word list the region names should be equal to the main word
464 list!
465
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000466- Other lines starting with '/' are reserved for future use. The ones that
467 are not recognized are ignored (but you do get a warning message).
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000468
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +0000469- A "/" may follow the word with the following items:
470 = Case must match exactly.
471 ? Rare word.
472 ! Bad (wrong) word.
473 digit A region in which the word is valid. If no regions are
474 specified the word is valid in all regions.
475
Bram Moolenaar3638c682005-06-08 22:05:14 +0000476Example:
477
478 # This is an example word list comment
479 /encoding=latin1 encoding of the file
480 /regions=uscagb regions "us", "ca" and "gb"
481 example word for all regions
Bram Moolenaar1f8a5f02005-07-01 22:41:52 +0000482 blah/12 word for regions "us" and "ca"
483 vim/! bad word
484 Campbell/?3 rare word in region 3 "gb"
485 's mornings/= keep-case word
Bram Moolenaar3638c682005-06-08 22:05:14 +0000486
Bram Moolenaar75c50c42005-06-04 22:06:24 +0000487
488FORMAT WITH AFFIX COMPRESSION
489
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000490There are two files: the basic word list and an affix file. The affixes are
491used to modify the basic words to get the full word list. This significantly
492reduces the number of words, especially for a language like Polish. This is
493called affix compression.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000494
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000495The format for the affix and word list files is mostly identical to what
496Myspell uses (the spell checker of Mozilla and OpenOffice.org). A description
497can be found here:
498 http://lingucomponent.openoffice.org/affix.readme ~
499Note that affixes are case sensitive, this isn't obvious from the description.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000500
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000501Vim supports a few extras. Hopefully Myspell will support these too some day.
502See |spell-affix-vim|.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000503
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000504The basic word list and the affix file are combined and turned into a binary
505spell file. All the preprocessing has been done, thus this file loads fast.
506The binary spell file format is described in the source code (src/spell.c).
507But only developers need to know about it.
508
509The preprocessing also allows us to take the Myspell language files and modify
510them before the Vim word list is made. The tools for this can be found in the
511"src/spell" directory.
512
513
Bram Moolenaar3638c682005-06-08 22:05:14 +0000514WORD LIST FORMAT *spell-dic-format*
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000515
516A very short example, with line numbers:
517
518 1 1234
519 2 aan
520 3 Als
521 4 Etten-Leur
522 5 et al.
523 6 's-Gravenhage
524 7 's-Gravenhaags
525 8 bedel/P
526 9 kado/1
527 10 cadeau/2
528
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000529The first line contains the number of words. Vim ignores it, but you do get
530an error message if it's not there. *E760*
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000531
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000532What follows is one word per line. There should be no white space before or
533after the word.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000534
535When the word only has lower-case letters it will also match with the word
536starting with an upper-case letter.
537
538When the word includes an upper-case letter, this means the upper-case letter
539is required at this position. The same word with a lower-case letter at this
540position will not match. When some of the other letters are upper-case it will
541not match either.
542
Bram Moolenaard042c562005-06-30 22:04:15 +0000543The word with all upper-case characters will always be OK.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000544
545 word list matches does not match ~
546 als als Als ALS ALs AlS aLs aLS
547 Als Als ALS als ALs AlS aLs aLS
548 ALS ALS als Als ALs AlS aLs aLS
549 AlS AlS ALS als Als ALs aLs aLS
550
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000551The KEP affix ID can be used to specifically match a word with identical case
Bram Moolenaare7566042005-06-17 22:00:15 +0000552only, see below |spell-affix-KEP|.
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000553
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000554Note in line 5 to 7 that non-word characters are used. You can include
555any character in a word. When checking the text a word still only matches
556when it appears with a non-word character before and after it. For Myspell a
557word starting with a non-word character probably won't work.
558
559After the word there is an optional slash and flags. Most of these flags are
Bram Moolenaard042c562005-06-30 22:04:15 +0000560letters that indicate the affixes that can be used with this word. These are
561specified with SFX and PFX lines in the .aff file. See the Myspell
562documentation.
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000563
564 *spell-affix-vim*
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000565A flag that Vim adds and is not in Myspell is the flag defined with KEP in the
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000566affix file. This has the meaning that case matters. This can be used if the
567word does not have the first letter in upper case at the start of a sentence.
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000568Example (assuming that = was used for KEP):
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000569
570 word list matches does not match ~
571 's morgens/= 's morgens 'S morgens 's Morgens
572 's Morgens 's Morgens 'S morgens 's morgens
573
574 *spell-affix-mbyte*
575The basic word list is normally in an 8-bit encoding, which is mentioned in
576the affix file. The affix file must always be in the same encoding as the
577word list. This is compatible with Myspell. For Vim the encoding may also be
578something else, any encoding that "iconv" supports. The "SET" line must
579specify the name of the encoding. When using a multi-byte encoding it's
Bram Moolenaard042c562005-06-30 22:04:15 +0000580possible to use more different affixes (but Myspell doesn't support that, thus
581you may not want to use it anyway).
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000582
Bram Moolenaare13305e2005-06-19 22:54:15 +0000583
584CHARACTER TABLES
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000585 *spell-affix-chars*
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000586When using an 8-bit encoding the affix file should define what characters are
587word characters (as specified with ENC). This is because the system where
588":mkspell" is used may not support a locale with this encoding and isalpha()
589won't work. For example when using "cp1250" on Unix.
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000590
Bram Moolenaare7566042005-06-17 22:00:15 +0000591 *E761* *E762* *spell-affix-FOL*
592 *spell-affix-LOW* *spell-affix-UPP*
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000593Three lines in the affix file are needed. Simplistic example:
594
Bram Moolenaare13305e2005-06-19 22:54:15 +0000595 FOL áëñ ~
596 LOW áëñ ~
597 UPP ÁËÑ ~
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000598
599All three lines must have exactly the same number of characters.
600
601The "FOL" line specifies the case-folded characters. These are used to
602compare words while ignoring case. For most encodings this is identical to
603the lower case line.
604
605The "LOW" line specifies the characters in lower-case. Mostly it's equal to
606the "FOL" line.
607
608The "UPP" line specifies the characters with upper-case. That is, a character
609is upper-case where it's different from the character at the same position in
610"FOL".
611
612ASCII characters should be omitted, Vim always handles these in the same way.
613When the encoding is UTF-8 no word characters need to be specified.
614
615 *E763*
Bram Moolenaar3b506942005-06-23 22:36:45 +0000616Vim allows you to use spell checking for several languages in the same file.
617You can list them in the 'spelllang' option. As a consequence all spell files
618for the same encoding must use the same word characters, otherwise they can't
619be combined without errors. If you get a warning that the word tables differ
620you may need to generate the .spl file again with |:mkspell|. Check the FOL,
621LOW and UPP lines in the used .aff file.
622
623The XX.ascii.spl spell file generated with the "-ascii" argument will not
624contain the table with characters, so that it can be combine with spell files
625for any encoding. The .add.spl files also do not contain the table.
Bram Moolenaar0cb032e2005-04-23 20:52:00 +0000626
Bram Moolenaare7566042005-06-17 22:00:15 +0000627
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000628MID-WORD CHARACTERS
629 *spell-midword*
630Some characters are only to be considered word characters if they are used in
631between two ordinary word characters. An example is the single quote: It is
632often used to put text in quotes, thus it can't be recognized as a word
633character, but when it appears in between word characters it must be part of
634the word. This is needed to detect a spelling error such as they'are. That
635should be they're, but since "they" and "are" are words themselves that would
636go unnoticed.
637
638These characters are defined with MIDWORD in the .aff file:
639
640 MIDWORD '- ~
641
642
Bram Moolenaare13305e2005-06-19 22:54:15 +0000643AFFIXES
644 *spell-affix-PFX* *spell-affix-SFX*
645The usual PFX (prefix) and SFX (suffix) lines are supported (see the Myspell
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000646documentation or the Aspell manual:
647http://aspell.net/man-html/Affix-Compression.html).
Bram Moolenaare13305e2005-06-19 22:54:15 +0000648
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000649Note that Myspell ignores any extra text after the relevant info. Vim
650requires this text to start with a "#" so that mistakes don't go unnoticed.
651Example:
652
653 SFX F 0 in [^i]n # Spion > Spionin ~
654 SFX F 0 nen in # Bauerin > Bauerinnen ~
655
656An extra item for Vim is the "rare" flag. It must come after the other
657fields, before a comment. When used then all words that use the affix will be
658marked as rare words. Example:
659
660 PFX F 0 nene . rare ~
661 SFX F 0 oin n rare # hardly ever used ~
662
663However, if the word also appears as a good word in another way it won't be
664marked as rare.
Bram Moolenaare13305e2005-06-19 22:54:15 +0000665
666 *spell-affix-PFXPOSTPONE*
667When an affix file has very many prefixes that apply to many words it's not
668possible to build the whole word list in memory. This applies to Hebrew (a
669list with all words is over a Gbyte). In that case applying prefixes must be
670postponed. This makes spell checking slower. It is indicated by this keyword
671in the .aff file:
672
673 PFXPOSTPONE ~
674
675Only prefixes without a chop string can be postponed, prefixes with a chop
676string will still be included in the word list.
677
678
679KEEP-CASE WORDS
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000680 *spell-affix-KEP*
681In the affix file a KEP line can be used to define the affix name used for
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000682keep-case words. Example:
683
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000684 KEP = ~
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000685
686See above for an example |spell-affix-vim|.
687
Bram Moolenaare13305e2005-06-19 22:54:15 +0000688
689RARE WORDS
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000690 *spell-affix-RAR*
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000691In the affix file a RAR line can be used to define the affix name used for
692rare words. Example:
693
694 RAR ? ~
695
696Rare words are highlighted differently from bad words. This is to be used for
697words that are correct for the language, but are hardly ever used and could be
Bram Moolenaar30abd282005-06-22 22:35:10 +0000698a typing mistake anyway. When the same word is found as good it won't be
699highlighted as rare.
700
701
702BAD WORDS
703 *spell-affix-BAD*
704In the affix file a BAD line can be used to define the affix name used for
705bad words. Example:
706
707 BAD ! ~
708
709This can be used to exclude words that would otherwise be good. For example
Bram Moolenaar9a50b1b2005-06-27 22:48:21 +0000710"the the" in the .dic file:
711
712 the the/! ~
713
714Once a word has been marked as bad it won't be undone by encountering the same
715word as good.
Bram Moolenaar45eeb132005-06-06 21:59:07 +0000716
717
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000718REPLACEMENTS *spell-affix-REP*
719
720In the affix file REP items can be used to define common mistakes. This is
721used to make spelling suggestions. The items define the "from" text and the
722"to" replacement. Example:
723
724 REP 4 ~
725 REP f ph ~
726 REP ph f ~
727 REP k ch ~
728 REP ch k ~
729
730The first line specifies the number of REP lines following. Vim ignores it.
Bram Moolenaard042c562005-06-30 22:04:15 +0000731Don't include simple one-character replacements or swaps. Vim will try these
732anyway. You can include whole words if you want to, but you might want to use
733the "file:" item in 'spellsuggest' instead.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000734
735
736SIMILAR CHARACTERS *spell-affix-MAP*
737
Bram Moolenaard042c562005-06-30 22:04:15 +0000738In the affix file MAP items can be used to define letters that are very much
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000739alike. This is mostly used for a letter with different accents. This is used
740to prefer suggestions with these letters substituted. Example:
741
742 MAP 2 ~
743 MAP eéëêè ~
744 MAP uüùúû ~
745
746The first line specifies the number of MAP lines following. Vim ignores it.
747
Bram Moolenaard042c562005-06-30 22:04:15 +0000748Each letter must appear in only one of the MAP items. It's a bit more
749efficient if the first letter is ASCII or at least one without accents.
Bram Moolenaare7566042005-06-17 22:00:15 +0000750
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000751
Bram Moolenaard042c562005-06-30 22:04:15 +0000752SOUND-A-LIKE *spell-affix-SAL*
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000753
754In the affix file SAL items can be used to define the sounds-a-like mechanism
755to be used. The main items define the "from" text and the "to" replacement.
Bram Moolenaard042c562005-06-30 22:04:15 +0000756Simplistic example:
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000757
758 SAL CIA X ~
759 SAL CH X ~
760 SAL C K ~
761 SAL K K ~
762
Bram Moolenaard042c562005-06-30 22:04:15 +0000763There are a few rules and this can become quite complicated. An explantion
764how it works can be found in the Aspell manual:
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000765http://aspell.net/man-html/Phonetic-Code.html.
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +0000766
767There are a few special items:
768
769 SAL followup true ~
770 SAL collapse_result true ~
771 SAL remove_accents true ~
772
773"1" has the same meaning as "true". Any other value means "false".
774
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000775
776SIMPLE SOUNDFOLDING *spell-affix-SOFOFROM* *spell-affix-SOFOTO*
777
778The SAL mechanism is complex and slow. A simpler mechanism is mapping all
779characters to another character, mapping similar sounding characters to the
780same character. At the same time this does case folding. You can not have
Bram Moolenaard042c562005-06-30 22:04:15 +0000781both SAL items and simple soundfolding.
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000782
783There are two items required: one to speficy the characters that are mapped
784and one that specifies the characters they are mapped to. They must have
785exactly the same number of characters. Example:
786
787 SOFOFROM abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ~
788 SOFOTO ebctefghejklnnepkrstevvkesebctefghejklnnepkrstevvkes ~
789
790In the example all vowels are mapped to the same character 'e'. Another
Bram Moolenaard042c562005-06-30 22:04:15 +0000791method would be to leave out all vowels. Some characters that sound nearly
792the same and are often mixed up, such as 'm' and 'n', are mapped to the same
793character. Don't do this too much, all words will start looking alike.
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000794
795Characters that do not appear in SOFOFROM will be left out, except that all
796white space is replaced by one space. Sequences of the same character in
797SOFOFROM are replaced by one.
798
799You can use the |soundfold()| function to try out the results. Or set the
800'verbose' option to see the score in the output of the |z?| command.
801
802
Bram Moolenaar217ad922005-03-20 22:37:15 +0000803 vim:tw=78:sw=4:ts=8:ft=help:norl: