1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
*spell.txt* For Vim version 7.0aa. Last change: 2005 Apr 24
VIM REFERENCE MANUAL by Bram Moolenaar
Spell checking *spell*
1. Quick start |spell-quickstart|
2. Generating a spell file |spell-mkspell|
9. Spell file format |spell-file-format|
{Vi does not have any of these commands}
Spell checking is not available when the |+syntax| feature has been disabled
at compile time.
==============================================================================
1. Quick start *spell-quickstart*
This command switches on spell checking: >
:setlocal spell spelllang=en_us
This switches on the 'spell' option and specifies to check for US English.
The words that are not recognized are highlighted with one of these:
SpellBad word not recognized
SpellRare rare word
SpellLocal wrong spelling for selected region
Vim only checks words for spelling, there is no grammar check.
To search for the next misspelled word:
*]s* *E756*
]s Move to next misspelled word after the cursor.
A count before the command can be used to repeat.
This uses the @Spell and @NoSpell clusters from syntax
highlighting, see |spell-syntax|.
*[s*
[s Like "]s" but search backwards, find the misspelled
word before the cursor.
*]S*
]S Like "]s" but only stop at bad words, not at rare
words or words for another region.
*[S*
[S Like "]S" but search backwards.
PERFORMANCE
Note that Vim does on-the-fly spellchecking. To make this work fast the
word list is loaded in memory. Thus this uses a lot of memory (1 Mbyte or
more). There might also be a noticable delay when the word list is loaded,
which happens when 'spelllang' is set. Each word list is only loaded once,
they are not deleted when 'spelllang' is made empty. When 'encoding' is set
the word lists are reloaded, thus you may notice a delay then too.
REGIONS
A word may be spelled differently in various regions. For example, English
comes in (at least) these variants:
en all regions
en_au Australia
en_ca Canada
en_gb Great Britain
en_nz New Zealand
en_us USA
Words that are not used in one region but are used in another region are
highlighted with SpellLocal.
Always use lowercase letters for the language and region names.
SPELL FILES
Vim searches for spell files in the "spell" subdirectory of the directories in
'runtimepath'. The name is: LL-XXX.EEE.spl, where:
LL the language name
-XXX optional addition
EEE the value of 'encoding'
Exceptions:
- Vim uses "latin1" when 'encoding' is "iso-8859-15". The euro sign doesn't
matter for spelling.
- When no spell file for 'encoding' is found "ascii" is tried. This only
works for languages where nearly all words are ASCII, such as English. It
helps when 'encoding' is not "latin1", such as iso-8859-2, and English text
is being edited.
Spelling for EBCDIC is currently not supported.
A spell file might not be available in the current 'encoding'. See
|spell-mkspell| about how to create a spell file. Converting a spell file
with "iconv" will NOT work!
*E758* *E759*
When loading a spell file Vim checks that it is properly formatted. If you
get an error the file may be truncated, modified or intended for another Vim
version.
WORDS
Vim uses a fixed method to recognize a word. This is independent of
'iskeyword', so that it also works in help files and for languages that
include characters like '-' in 'iskeyword'. The word characters do depend on
'encoding'.
A word that starts with a digit is always ignored.
SYNTAX HIGHLIGHTING *spell-syntax*
Files that use syntax highlighting can specify where spell checking should be
done:
everywhere default
in specific items use "contains=@Spell"
everywhere but specific items use "contains=@NoSpell"
Note that mixing @Spell and @NoSpell doesn't make sense.
==============================================================================
2. Generating a spell file *spell-mkspell*
Vim uses a binary file format for spelling. This greatly speeds up loading
the word list and keeps it small.
You can create a Vim spell file from the .aff and .dic files that Myspell
uses. Myspell is used by OpenOffice.org and Mozilla. You should be able to
find them here:
http://lingucomponent.openoffice.org/spell_dic.html
:mksp[ell] [-ascii] {outname} {inname} ... *:mksp* *:mkspell*
Generate spell file {outname}.spl from Myspell files
{inname}.aff and {inname}.dic.
When the [-ascii] argument is present, words with
non-ascii characters are skipped. The resulting file
ends in "ascii.spl". Otherwise the resulting file
ends in "ENC.spl", where ENC is the value of
'encoding'.
Multiple {inname} arguments can be given to combine
regions into one Vim spell file. Example: >
:mkspell ~/.vim/spell/en /tmp/en_US /tmp/en_CA /tmp/en_AU
< This combines the English word lists for US, CA and AU
into one en.spl file.
Up to eight regions can be combined. *E754* *755*
Since you might want to change the word list for use with Vim the following
procedure is recommended:
1. Obtain the xx_YY.aff and xx_YY.dic files from Myspell.
2. Make a copy of these files to xx_YY.orig.aff and xx_YY.orig.dic.
3. Change the xx_YY.aff and xx_YY.dic files to remove bad words, add missing
words, define word characters with FOL/LOW/UPP, etc. The distributed
"src/spell/*.diff" files can be used.
4. Set 'encoding' to the desired encoding and use |:mkspell| to generate the
Vim spell file.
5. Try out the spell file with ":set spell spelllang=xx_YY".
When the Myspell files are updated you can merge the differences:
1. Obtain the new Myspell files as xx_YY.new.aff and xx_UU.new.dic.
2. Use Vimdiff to see what changed: >
vimdiff xx_YY.orig.dic xx_YY.new.dic
3. Take over the changes you like in xx_YY.dic.
You may also need to change xx_YY.aff.
4. Rename xx_YY.new.dic to xx_YY.orig.dic and xx_YY.new.aff to xx_YY.new.aff.
==============================================================================
9. Spell file format *spell-file-format*
This is the format of the files that are used by the person who creates and
maintains a word list.
Note that we avoid the word "dictionary" here. That is because the goal of
spell checking differs from writing a dictionary (as in the book). For
spelling we need a list of words that are OK, thus need not to be highlighted.
Names will not appear in a dictionary, but do appear in a word list. And
some old words are rarely used and are common misspellings. These do appear
in a dictionary but not in a word list.
There are two files: the basic word list and an affix file. The affixes are
used to modify the basic words to get the full word list. This significantly
reduces the number of words, especially for a language like Polish. This is
called affix compression.
The format for the affix and word list files is mostly identical to what
Myspell uses (the spell checker of Mozilla and OpenOffice.org). A description
can be found here:
http://lingucomponent.openoffice.org/affix.readme ~
Note that affixes are case sensitive, this isn't obvious from the description.
Vim supports a few extras. Hopefully Myspell will support these too some day.
See |spell-affix-vim|.
The basic word list and the affix file are combined and turned into a binary
spell file. All the preprocessing has been done, thus this file loads fast.
The binary spell file format is described in the source code (src/spell.c).
But only developers need to know about it.
The preprocessing also allows us to take the Myspell language files and modify
them before the Vim word list is made. The tools for this can be found in the
"src/spell" directory.
WORD LIST FORMAT *spell-wordlist-format*
A very short example, with line numbers:
1 1234
2 aan
3 Als
4 Etten-Leur
5 et al.
6 's-Gravenhage
7 's-Gravenhaags
8 bedel/P
9 kado/1
10 cadeau/2
The first line contains the number of words. Vim ignores it. *E760*
What follows is one word per line. There should be no white space after the
word.
When the word only has lower-case letters it will also match with the word
starting with an upper-case letter.
When the word includes an upper-case letter, this means the upper-case letter
is required at this position. The same word with a lower-case letter at this
position will not match. When some of the other letters are upper-case it will
not match either.
The same word with all upper-case characters will always be OK.
word list matches does not match ~
als als Als ALS ALs AlS aLs aLS
Als Als ALS als ALs AlS aLs aLS
ALS ALS als Als ALs AlS aLs aLS
AlS AlS ALS als Als ALs aLs aLS
Note in line 5 to 7 that non-word characters are used. You can include
any character in a word. When checking the text a word still only matches
when it appears with a non-word character before and after it. For Myspell a
word starting with a non-word character probably won't work.
After the word there is an optional slash and flags. Most of these flags are
letters that indicate the affixes that can be used with this word.
*spell-affix-vim*
A flag that Vim adds and is not in Myspell is the "=" flag. This has the
meaning that case matters. This can be used if the word does not have the
first letter in upper case at the start of a sentence. Example:
word list matches does not match ~
's morgens/= 's morgens 'S morgens 's Morgens
's Morgens 's Morgens 'S morgens 's morgens
*spell-affix-mbyte*
The basic word list is normally in an 8-bit encoding, which is mentioned in
the affix file. The affix file must always be in the same encoding as the
word list. This is compatible with Myspell. For Vim the encoding may also be
something else, any encoding that "iconv" supports. The "SET" line must
specify the name of the encoding. When using a multi-byte encoding it's
possible to use more different affixes.
Performance hint: Although using affixes reduces the number of words, it
reduces the speed. It's a good idea to put all the often used words in the
word list with the affixes prepended/appended.
*spell-affix-chars*
The affix file should define the word characters when using an 8-bit encoding
(as specified with ENC). This is because the system where ":mkspell" is used
may not support a locale with this encoding and isalpha() won't work. For
example when using "cp1250" on Unix.
*E761* *E762*
Three lines in the affix file are needed. Simplistic example:
FOL áëñáëñ
LOW áëñáëñ
UPP áëñÁËÑ
All three lines must have exactly the same number of characters.
The "FOL" line specifies the case-folded characters. These are used to
compare words while ignoring case. For most encodings this is identical to
the lower case line.
The "LOW" line specifies the characters in lower-case. Mostly it's equal to
the "FOL" line.
The "UPP" line specifies the characters with upper-case. That is, a character
is upper-case where it's different from the character at the same position in
"FOL".
ASCII characters should be omitted, Vim always handles these in the same way.
When the encoding is UTF-8 no word characters need to be specified.
*E763*
All spell files for the same encoding must use the same word characters,
otherwise they can't be combined without errors. The XX.ascii.spl spell file
generated with the "-ascii" argument will not contain the table with
characters, so that it can be combine with spell files for any encoding.
vim:tw=78:sw=4:ts=8:ft=help:norl:
|