Spell checking

aspell is a command-line spell checker. It is a replacement for the older ispell. It can be used to manage dictionaries, to check a complete file, or words typed in your terminal, among other uses.

We can invoke aspell this way:

<code>$ aspell -a --lang=en
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.3)</code>

This leaves us with a prompt in which we can type a word. For instance, if we type:

<code>@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.3)
hello
*

</code>

The asterisk indicates that aspell found the word in the dictionary. On the contrary, if we type:

<code>@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.3)
rescoe
&amp; rescoe 15 0: Roscoe, rescue, rescuer, Rosco, resow, resole, rescale, rescued, rescues, fresco, recce, Reece, rescan, Roscoe's, Rosco's

</code>

We are presented with a list of options.

One of the nice features of aspell is that it can check a complete file. This way, it interactively asks the user to take an action for every misspelled word. For example:

<code>$ cat test.txt
Simple text to check
the use of aspell from inside Vim
The following werd was misspelled</code>

If we ran:

<code>$ aspell --lang=en -c test.txt</code>

we are presented with the following screen:

<code>
Simple text to check
the use of aspell from inside Vim
The following werd was misspelled


1) Aspell                                                                        6) Aspell's
2) asp ell                                                                       7) Ascella
3) asp-ell                                                                       8) spill
4) Ispell                                                                        9) Ispell's
5) spell
i) Ignore                                                                        I) Ignore all
r) Replace                                                                       R) Replace all
a) Add                                                                           l) Add Lower
b) Abort                                                                         x) Exit


?
</code>

This is very interesting as we can edit a file and check the spelling, but it would be nicer if we could spell check our text directly from our favorite editor…

You saw this coming, didn’t you? 🙂

Spell checking from inside Vim

While editing the same test.txt file with Vim, we can type the following:

<code>:!aspell --lang=en -c %</code>

This opens the aspell prompt which enables us to correct the misspelled words. Once we are done, Vim notifies us of the modification of the file:

<code>W11: Warning: File "test.txt" has changed since editing started
See ":help W11" for more info.
[O]K, (L)oad File: </code>

Typing L returns to Vim with the corrected file.

If we want to check a single word, we can type the following:

<code>:!echo &lt;cword&gt; | aspell pipe --lang=en&lt;CR&gt;</code>

<cword> expands to the word under the cursor. Then we pipe this word to aspell for spell checking. This is somehow long to write, so it could be a good idea to define a macro:

<code>:map &lt;F4&gt; &lt;Esc&gt;:!echo &lt;cword&gt; | aspell pipe --lang=en&lt;CR&gt;</code>

Enjoy!