sponsor Vim development Vim logo Vim Book Ad

SpellCheck : Work with spelling errors.

 script karma  Rating 13/9, Downloaded by 1579    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
script type
Vim offers built-in spell checking; when you enable it via 'spell' and
'spelllang', you can jump to the highlighted spelling errors in the buffer via
]s. With spelling errors scattered across a large document, Vim does not
provide an overview or report about the overall spell situation.

This plugin populates the quickfix-list with all spelling errors found in a
buffer to give you that overview. You can use the built-in quickfix features
to navigate to the first occurrence of a particular spell error. You can also
manage the spelling errors (mark as good / bad word, globally replace with
suggestion) directly from the quickfix window via the usual zg, zw, z=
etc. mappings.

A typical workflow (e.g. when composing email, commit messages, or any form of
documentation) includes writing and/or quitting the buffer, unless some
remaining spelling errors require further intervention. This plugin offers
auxiliary enhanced variants of :bdelete, :write and :quit that check for
spelling errors and only execute the action if none were found. So by using
these replacement commands, you'll never send or commit messages full of
embarrassing typos any more!

:[range]SpellCheck[!]   Show all spelling errors as a quickfix list.
                        For multiple occurrences of the same error, the first
                        location and the number of occurrences is shown.
                        If [!] is not given the first error is jumped to.

                        In the quickfix list, spelling errors from other
                        buffers are kept, so you can use something like
                            :argdo SpellCheck
                       to gather the spelling errors from multiple buffers.

:[range]SpellLCheck[!]  Same as :SpellCheck, except the location list for the
                        current window is used instead of the quickfix list.

                        Inside the quickfix window, the following mappings are
                        remapped so that they operate on the target spell
                        error: zg, zG, zw, zW, zug, zuG, zuw,
                        zuW, z=, u
                        For z=, all identical misspellings in the buffer are
                        replaced with the chosen suggestion (via
                        You can also quickly undo the last spell suggestion
                        from the quickfix window (i.e. without switching to
                        the target buffer) via u.
                        For the other commands, the taken action is appended
                        to the quickfix list entry, so that the list serves as
                        a record of done actions (until you refresh the list
                        with a new :SpellCheck).

The following set of commands just issue an error when spelling errors exist
in the buffer or passed [range] of lines.

:BDeleteUnlessSpellError[!]     :bdelete the current buffer, unless it
                                contains spelling errors.
:WriteUnlessSpellError[!] [++opt] [file]
                                :write the current buffer, unless it
                                contains spelling errors.
:WriteDeleteUnlessSpellError[!]  [++opt] [file]
                                :write and :bdelete the current buffer,
                                unless it contains spelling errors.
:XitUnlessSpellError[!]         :write  the current buffer and :quit,
                                unless it contains spelling errors.

:NextUnlessSpellError[!] [++opt] [file]
                                Edit :next file, unless the current buffer
                                contains spelling errors.

This set of commands automatically opens the quickfix list in case of spelling
error in the buffer or passed [range] of lines.

:BDeleteOrSpellCheck[!]         :bdelete the current buffer, or show the
                                spelling errors in the quickfix list.
:WriteOrSpellCheck[!] [++opt] [file]
                                :write the current buffer, or show the
                                spelling errors in the quickfix list.
:WriteDeleteOrSpellCheck[!] [++opt] [file]
                                :write and :bdelete the current buffer,
                                or show the spelling errors in the quickfix
:XitOrSpellCheck[!]             :write the current buffer and :quit, or
                                show the spelling errors in the quickfix list.

:NextOrSpellCheck[!] [++opt] [file]
                                Edit :next file, or show the current
                                buffer's spelling errors in the quickfix list.

:UpdateAndSpellCheck[!]         :update the current buffer, and show any
                                spelling errors in the quickfix list.

                                A [!] is passed to the :write / :bdelete /
                                :quit commands.
install details
This script is packaged as a vimball. If you have the "gunzip" decompressor
in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress
the archive first, e.g. using WinZip. Inside Vim, install by sourcing the
vimball or via the :UseVimball command.
    vim SpellCheck*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.001 or

For a permanent configuration, put the following commands into your vimrc:

If you don't want the auxiliary commands, just the core :SpellCheck command,
    let g:SpellCheck_DefineAuxiliaryCommands = 0
If you just want some of the auxiliary commands, or under different names, or
similar commands, you can easily define them yourself, as the core spell check
functionality is available as global autoload functions. Have a look at
plugin/SpellCheck.vim for inspiration.

If you don't want the SpellCheck-mappings that allow you to manage the spell
errors directly from the quickfix window, use:
    let g:SpellCheck_DefineQuickfixMappings = 0

The :SpellCheck command captures not just the misspelled word, but also some
text around it, to provide context in the quickfix list. The number of
occurrences of a particular spell error is set at:
    let g:SpellCheck_ErrorContextNum = 99
You can tweak that, reduce it to 1 to only show the first, or 0 to completely
turn off context.

What text around the current spell error gets captured can be tweaked via a
regular expression that contains a %s parameter, which is replaced with the
atom for the spell error start position. As Vim uses a special,
spellfile-dependent definition of word characters, these can be tweaked

The plugin can provide additional syntax highlighting for the quickfix window
when it contains spell errors; to turn this off, use:
    let g:SpellCheck_QuickfixHighlight = 0

To change the highlighting colors, redefine (after any :colorscheme command)
or link the two highlight groups:
    highlight link qfSpellErrorWord             SpellBad
    highlight link qfSpellErrorWordInContext    Normal
    highlight link qfSpellContext               SpecialKey

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
SpellCheck-1.30.vmb.gz 1.30 2014-07-24 7.0 Ingo Karkat - ENH: Show words surrounding the spell error. The number of captured occurrences is controlled by g:SpellCheck_ErrorContextNum, what gets captured by g:SpellCheck_ErrorContextPattern. Thanks to Enno Nagel for the suggestion.
- ENH: Add syntax highlighting for the misspelled word, the error context text, and occurrences of the misspelled word inside the context. Enno Nagel also suggested this.
- FIX: Quickfix mappings are gone when closing and reopening the quickfix window (:cclose | copen), because a new scratch buffer is used, but the autocmd BufRead quickfix has been cleared.
SpellCheck-1.21.vmb.gz 1.21 2013-09-23 7.0 Ingo Karkat - Add :NextUnlessSpellError and :NextOrSpellCheck auxiliary commands.
- Allow to pass optional [++opt] [file] arguments to the :Write... commands.
- Add dependency to ingo-library (vimscript #4433). *** You need to separately install ingo-library (vimscript #4433) version 1.001 (or higher)! ***
SpellCheck.vba.gz 1.20 2012-05-08 7.0 Ingo Karkat - FIX: Line range is not defined and passed for :BDeleteOrSpellCheck and other :...OrSpellCheck commands, resulting in a script error.
- ENH: Allow [range] for :BDeleteUnlessSpellError and other :...UnlessSpellError commands, too.
SpellCheck.vba.gz 1.13 2012-05-02 7.0 Ingo Karkat ENH: In the quickfix list, apply undo via |u| to the target buffer to allow a quick revert of a spell correction.
SpellCheck.vba.gz 1.12 2012-05-01 7.0 Ingo Karkat ENH: Allow spell checking of partial buffers by allowing [range] for :SpellCheck command.
SpellCheck.vba.gz 1.11 2012-04-30 7.0 Ingo Karkat ENH: Capture corrected text and include in quickfix status message.
SpellCheck.vba.gz 1.10 2012-04-30 7.0 Ingo Karkat ENH: Allow to manage the spelling errors (mark as good / bad word, globally replace with suggestion) directly from the quickfix window via the usual zg, zw, z= etc. mappings.
SpellCheck.vba.gz 1.01 2011-12-14 7.0 Ingo Karkat ENH: Allow accumulating spelling errors from multiple buffers (e.g. via :argdo SpellCheck).
SpellCheck.vba.gz 1.00 2011-12-09 7.0 Ingo Karkat Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo