6

I am a programmer and use Vim primarily for that, but I have found that enabling Vim's spell check is a somewhat useful feature to have just to help slightly incentivize cleaning up the parts of files that are written in English.

Now what I thought about just now is I think it would be cool if I could have this system mark certain arbitrary word sequences like "the the" as an error for me. Is this possible?

I know that I can use zw to mark a word as bad, but I want to do it for a sequence of words that I want to also treat as wrong (but which may be made up of words that are fine).

(use :set spell to enable spell check in Vim)

  • Wait a second... So I wrote this question before testing it, and it looks like the spell check ALREADY marks "the the" as a "spelling" error. Mind blown. Question still remains, though. How to add to this list? – Steven Lu Feb 19 '15 at 1:36
  • :help spell-BAD – Doorknob Feb 19 '15 at 1:51
9

Alright, so I looked it up this way since I had Vim's source code lying around:

$ cd ~/Documents/vim
$ ack 'the the'

...

runtime/doc/spell.txt
399:It can also be used to recognize "the the" and highlight it.
1206:"the the" in the .dic file:
1208:   the the/! ~
1463:   REP the_the the ~

...

OK so Vim's documentation itself appears to explain the situation (though not to my own satisfaction):

WORD COMBINATIONS

It is possible to spell-check words that include a space. This is used to recognize words that are invalid when used by themselves, e.g. for "et al.". It can also be used to recognize "the the" and highlight it.

There's a bunch more documentation that goes in depth into how and what the spell system is capable of. It's mostly sort of boring.

I also discovered the best way to easily add a word sequence to the "bad spelling" list. Just use zw in visual mode after selecting the sequence you want to mark as bad (the mnemonic is w for "wrong"). It works great. What it does automatically is add the word sequence to the spellfile such as ~/.vim/spell/en.utf-8.add in a line ending with /! which means it's a "bad word".

  • The bolding makes the zw look like capitals. – muru Mar 17 '15 at 4:10
  • @muru edited... – Steven Lu Mar 17 '15 at 15:05

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.