blob: 04e1cfd0be03ab72c487546b8173a08fbc24c8aa [file] [log] [blame]
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001*spell.txt* For Vim version 7.0aa. Last change: 2005 Apr 15
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 Moolenaar13fcaaf2005-04-15 21:13:42 +0000102. Generating a spell file |spell-mkspell|
119. Spell file format |spell-file-format|
Bram Moolenaar217ad922005-03-20 22:37:15 +000012
13{Vi does not have any of these commands}
14
15Spell checking is not available when the |+syntax| feature has been disabled
16at compile time.
17
18==============================================================================
191. Quick start *spell-quickstart*
20
21This command switches on spell checking: >
22
23 :setlocal spell spelllang=en_us
24
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000025This switches on the 'spell' option and specifies to check for US English.
Bram Moolenaar217ad922005-03-20 22:37:15 +000026
27The 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
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000032Vim only checks words for spelling, there is no grammar check.
33
34To search for the next misspelled word:
35
36 *]s* *E756*
37]s Move to next misspelled word after the cursor.
38
39 *[s*
40[s Move to next misspelled word before the cursor.
41 DOESN'T WORK YET!
42
Bram Moolenaar217ad922005-03-20 22:37:15 +000043
Bram Moolenaar6bb68362005-03-22 23:03:44 +000044PERFORMANCE
45
46Note that Vim does on-the-fly spellchecking. To make this work fast the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000047word list is loaded in memory. Thus this uses a lot of memory (1 Mbyte or
Bram Moolenaar6bb68362005-03-22 23:03:44 +000048more). There might also be a noticable delay when the word list is loaded,
49which happens when 'spelllang' is set. Each word list is only loaded once,
50they are not deleted when 'spelllang' is made empty. When 'encoding' is set
51the word lists are reloaded, thus you may notice a delay then too.
52
53
Bram Moolenaar217ad922005-03-20 22:37:15 +000054REGIONS
55
56A word may be spelled differently in various regions. For example, English
57comes in (at least) these variants:
58
59 en all regions
60 en_us US
61 en_gb Great Britain
62 en_ca Canada
63
64Words that are not used in one region but are used in another region are
65highlighted with SpellLocal.
66
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000067Always use lowercase letters for the language and region names.
Bram Moolenaar217ad922005-03-20 22:37:15 +000068
69
70SPELL FILES
71
72Vim searches for spell files in the "spell" subdirectory of the directories in
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000073'runtimepath'. The name is: LL-XXX.EEE.spl, where:
74 LL the language name
75 -XXX optional addition
76 EEE the value of 'encoding'
Bram Moolenaar217ad922005-03-20 22:37:15 +000077
78Exception: Vim uses "latin1" when 'encoding' is "iso-8859-15". The euro sign
79doesn't matter for spelling.
80
Bram Moolenaar6bb68362005-03-22 23:03:44 +000081Spelling for EBCDIC is currently not supported.
82
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000083A spell file might not be available in the current 'encoding'. See
84|spell-mkspell| about how to create a spell file. Converting a spell file
85with "iconv" will NOT work.
Bram Moolenaar217ad922005-03-20 22:37:15 +000086
87If a spell file only uses ASCII characters the encoding can be omitted. This
88is useful for English: "en.spl" The file with encoding is checked first, thus
89you could have one with encoding that includes words with non-ASCII characters
90and use the ASCII file as a fall-back.
91
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +000092 *E758* *E759*
93When loading a spell file Vim checks that it is properly formatted. If you
94get an error the file may be truncated, modified or for another Vim version.
95
Bram Moolenaar6bb68362005-03-22 23:03:44 +000096
97WORDS
98
99Vim uses a fixed method to recognize a word. This is independent of
100'iskeyword', so that it also works in help files and for languages that
101include characters like '-' in 'iskeyword'. The word characters do depend on
102'encoding'.
103
104A word that starts with a digit is always ignored.
105
106
107SYNTAX HIGHLIGHTING
108
109Files that use syntax highlighting can specify where spell checking should be
110done:
111
112 everywhere default
113 in specific items use "contains=@Spell"
114 everywhere but specific items use "contains=@NoSpell"
115
116Note that mixing @Spell and @NoSpell doesn't make sense.
117
Bram Moolenaar217ad922005-03-20 22:37:15 +0000118==============================================================================
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001192. Generating a spell file *spell-mkspell*
Bram Moolenaar217ad922005-03-20 22:37:15 +0000120
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000121Vim uses a binary file format for spelling. This greatly speeds up loading
122the word list and keeps it small.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000123
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000124You can create a Vim spell file from the .aff and .dic files that Myspell
125uses. Myspell is used by OpenOffice.org and Mozilla. You should be able to
126find them here:
127 http://lingucomponent.openoffice.org/spell_dic.html
Bram Moolenaar217ad922005-03-20 22:37:15 +0000128
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000129:mksp[ell] {outname} {inname} ... *:mksp* *:mkspell*
130 Generate spell file {outname}.spl from Myspell files
131 {inname}.aff and {inname}.dic.
132 Multiple {inname} arguments can be given to combine
133 regions into one Vim spell file. Example: >
134 :mkspell ~/.vim/spell/en /tmp/en_US /tmp/en_CA /tmp/en_AU
135< This combines the English word lists for US, CA and AU
136 into one en.spl file.
137 Up to eight regions can be combined. *E754* *755*
Bram Moolenaar217ad922005-03-20 22:37:15 +0000138
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000139Since you might want to change the word list for use with Vim the following
140procedure is recommended:
Bram Moolenaar217ad922005-03-20 22:37:15 +0000141
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001421. Obtain the xx_YY.aff and xx_YY.dic files from Myspell.
1432. Make a copy of these files to xx_YY.orig.aff and xx_YY.orig.dic.
1443. Change the xx_YY.aff and xx_YY.dic files to remove bad words, add missing
145 words, etc.
1464. Use |:mkspell| to generate the Vim spell file and try it out.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000147
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000148When the Myspell files are updated you can merge the differences:
1495. Obtain the new Myspell files as xx_YY.new.aff and xx_UU.new.dic.
1506. Use Vimdiff to see what changed: >
151 vimdiff xx_YY.orig.dic xx_YY.new.dic
1527. Take over the changes you like in xx_YY.dic.
153 You may also need to change xx_YY.aff.
1548. 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 +0000155
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000156==============================================================================
1579. Spell file format *spell-file-format*
Bram Moolenaar217ad922005-03-20 22:37:15 +0000158
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000159This is the format of the files that are used by the person who creates and
160maintains a word list.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000161
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000162Note that we avoid the word "dictionary" here. That is because the goal of
163spell checking differs from writing a dictionary (as in the book). For
164spelling we need a list of words that are OK, thus need not to be highlighted.
165Names will not appear in a dictionary, but do appear in a word list. And
166some old words are rarely used and are common misspellings. These do appear
167in a dictionary but not in a word list.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000168
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000169There are two files: the basic word list and an affix file. The affixes are
170used to modify the basic words to get the full word list. This significantly
171reduces the number of words, especially for a language like Polish. This is
172called affix compression.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000173
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000174The format for the affix and word list files is mostly identical to what
175Myspell uses (the spell checker of Mozilla and OpenOffice.org). A description
176can be found here:
177 http://lingucomponent.openoffice.org/affix.readme ~
178Note that affixes are case sensitive, this isn't obvious from the description.
179Vim supports a few extras. Hopefully Myspell will support these too some day.
180See |spell-affix-vim|.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000181
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000182The basic word list and the affix file are combined and turned into a binary
183spell file. All the preprocessing has been done, thus this file loads fast.
184The binary spell file format is described in the source code (src/spell.c).
185But only developers need to know about it.
186
187The preprocessing also allows us to take the Myspell language files and modify
188them before the Vim word list is made. The tools for this can be found in the
189"src/spell" directory.
190
191
192WORD LIST FORMAT *spell-wordlist-format*
193
194A very short example, with line numbers:
195
196 1 1234
197 2 aan
198 3 Als
199 4 Etten-Leur
200 5 et al.
201 6 's-Gravenhage
202 7 's-Gravenhaags
203 8 bedel/P
204 9 kado/1
205 10 cadeau/2
206
207The first line contains the number of words. Vim ignores it. *E760*
208
209What follows is one word per line. There should be no white space after the
210word.
211
212When the word only has lower-case letters it will also match with the word
213starting with an upper-case letter.
214
215When the word includes an upper-case letter, this means the upper-case letter
216is required at this position. The same word with a lower-case letter at this
217position will not match. When some of the other letters are upper-case it will
218not match either.
219
220The same word with all upper-case characters will always be OK.
221
222 word list matches does not match ~
223 als als Als ALS ALs AlS aLs aLS
224 Als Als ALS als ALs AlS aLs aLS
225 ALS ALS als Als ALs AlS aLs aLS
226 AlS AlS ALS als Als ALs aLs aLS
227
228Note in line 5 to 7 that non-word characters are used. You can include
229any character in a word. When checking the text a word still only matches
230when it appears with a non-word character before and after it. For Myspell a
231word starting with a non-word character probably won't work.
232
233After the word there is an optional slash and flags. Most of these flags are
234letters that indicate the affixes that can be used with this word.
235
236 *spell-affix-vim*
237A flag that Vim adds and is not in Myspell is the "=" flag. This has the
238meaning that case matters. This can be used if the word does not have the
239first letter in upper case at the start of a sentence. Example:
240
241 word list matches does not match ~
242 's morgens/= 's morgens 'S morgens 's Morgens
243 's Morgens 's Morgens 'S morgens 's morgens
244
245 *spell-affix-mbyte*
246The basic word list is normally in an 8-bit encoding, which is mentioned in
247the affix file. The affix file must always be in the same encoding as the
248word list. This is compatible with Myspell. For Vim the encoding may also be
249something else, any encoding that "iconv" supports. The "SET" line must
250specify the name of the encoding. When using a multi-byte encoding it's
251possible to use more different affixes.
252
253Performance hint: Although using affixes reduces the number of words, it
254reduces the speed. It's a good idea to put all the often used words in the
255word list with the affixes prepended/appended.
Bram Moolenaar217ad922005-03-20 22:37:15 +0000256
257
258 vim:tw=78:sw=4:ts=8:ft=help:norl: