0

I've got the following obviously misspelled file:

bla blar blar

When I open it as "bla.txt" and run :setlocal spell vim rightly points out all three words as misspellings. However, if I mv the file to bla.js and open it again, turning on spelling does not highlight anything. It will select spelling mistakes inside of comments, however. Is there a way to enable spell checking of, say, string literals (or everything?)

  • At a guess, the syntax for JS disabled spell checking in many of its syntax elements (usually comments are the only things that get spell checked in code) – D. Ben Knoble Oct 11 at 12:32
  • Where would one go to configure that? I notice that the help says: Files that use syntax highlighting can specify where spell checking should be done so there's got to be a way. – Eamonn M.R. Oct 11 at 12:49
  • Also, confirmed that it checks spelling in comments; will update question title. – Eamonn M.R. Oct 11 at 12:54
2

$VIMRUNTIME/syntax/javascript.vim has some syntax items (specifically, the comments) which contains=@Spell. Therefore, if user sets both syntax on and set spell, only such items will be spell-checked, as explained in :h spell-syntax.

To override this you have to issue the command:

syntax spell toplevel

See :h syn-spell for more info.

Also note that simply deleting .vimrc leaves filetypes / syntax on, as Vim uses $VIMRUNTIME/defaults.vim in this case. So always run vim --clean when trying to check the true defaults.

  • 2
    Eh, the js files dont set syntax on—users do. Minor nit though. – D. Ben Knoble Oct 11 at 13:37
  • @D.BenKnoble I stand corrected. – Matt Oct 11 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.