vimtricks.wiki Concise Vim tricks, one at a time.

How do I make Vim spell check CamelCase and mixedCase identifiers as individual words?

Answer

:set spelloptions=camel

Explanation

By default, Vim treats camelCase as a single word and flags it as a spelling error even when both camel and case are correctly spelled. Setting spelloptions=camel (added in Vim 8.1.0994) tells the spell checker to split CamelCase and MixedCase tokens at capital letter boundaries before checking each component independently.

This is especially useful when editing code comments, commit messages, or Markdown documentation that contains identifier names.

How it works

  • spelloptions=camel — enables CamelCase splitting for spell checking
  • Vim splits at each transition from a lowercase letter to an uppercase letter
  • Each component is checked independently against the active spell file
  • Does not affect the buffer text — it only changes how the spell checker tokenizes words

Example

With :set spell but without spelloptions=camel:

The getUserName function returns a string.
     ^^^^^^^^^^^                           <- flagged as misspelled

After :set spelloptions=camel:

The getUserName function returns a string.
                                          <- correctly split to get/User/Name, all OK

Tips

  • Combine with :set spell spelllang=en_us in your config for full effect
  • Works with all spell navigation commands: ]s (next error), [s (prev), z= (suggest)
  • Add to your vimrc: set spelloptions=camel
  • Also accepts the noplainbuffer value: set spelloptions=camel,noplainbuffer
  • Requires Vim 8.1+ or any Neovim version

Next

How do I sort lines numerically so that 10 sorts after 2 rather than before it?