Tim
Tim

Reputation: 14164

Ignore one "misspelling" in Vim

Is there a way to tell Vim not to highlight a word once? For example, in "the password is abc123", I don't want to add abc123 to the wordlist, but still wouldn't like the big red rectangle around it.

Clarification: I'm looking for a command that makes the spell checker ignore the current word (or last misspelling).

Upvotes: 32

Views: 7758

Answers (2)

sidyll
sidyll

Reputation: 59307

Without having the word stored somewhere, it's hard (not to say impossible) to ignore it always.

But, if you are looking to ignore the word really once, that is only for a moment, you can add it to the internal list with the zG command.

                                                             *zG*
zG              Like "zg" but add the word to the internal word list
                |internal-wordlist|.


                                               *internal-wordlist*
The internal word list is used for all buffers where 'spell' is set.  It is
not stored, it is lost when you exit Vim.  It is also cleared when 'encoding'
is set.

Upvotes: 48

nelstrom
nelstrom

Reputation: 19562

When your cursor is positioned on a word that is highlighted as misspelled you can add it to your wordlist by pressing zg. Vim allows you to load more than one wordlist at a time, which makes it possible to have (for example) a global wordlist, and a project specific wordlist.

By default, when you run zg it will add the current word to the first spellfile it finds in your runtime path for the current encoding. In my case, that turns out to be ~/.vim/spell/en.utf-8.add when I'm working with UTF-8 encoding. Try running the following commands:

:setlocal spellfile+=~/.vim/spell/en.utf-8.add
:setlocal spellfile+=oneoff.utf-8.add

That will set you up so that zg (or 1zg) adds the current word to your default spellfile. But running 2zg would add the current word to a file called oneoff.utf-8.add, in the same directory as the file that you are working on. If the file doesn't exist, Vim will try to create it for you.

When you open the file again in the future, you will have to run the same two commands to make Vim check the oneoff.utf-8.add spellfile. Unfortunately, Vim does not allow you to set the spellfile option in a modeline, so if you want to run these commands automatically when the file opens, you would have to find some other way. This question includes a few ideas on how you might proceed.

Upvotes: 38

Related Questions