Suppose I am writing in a markdown file, and I am using odd naming conventions like 'thisFileNameIsGood'. Spell checker will also mark it as wrong along with the names that the spell checker doesn't recognize. Now I can always add those odd words to the dictionary. But that won't be a right thing to do. I can mark those words safe with zG, but that won't stay as I restart Vim.

Upon searing internet, I found this question: How to exclude capitalized words from spell checking in Vim. In the accepted answer to that question, someone suggested using this command:

syn match myExCapitalWords +\<\w*[A-Z]\S*\>+ contains=@NoSpell

In that command the +\<\w*[A-Z]\S*\>+ part is a pattern where + denotes that beginning and ending of the pattern. First, I used that command blindingly without understanding each and every part of it. The desired effect was that all words with at least one capital letter would be exempted from spell checking. But after using that command, even wrongly spelled all lowercase words were not marked as wrongly spelled.

To make things simpler, I changed the command to:

syn match myExCapitalWords +\<\h\l*\>+ contains=@Spell

Now the command is supposed to direct the spell checker to spell check only words that are begining with [a-zA-Z] followed by zero or more number of lowercase letters [a-z]. The purpose of this simplification was that now the command will direct the splell checker only to check for wrong spells in words that begins with [a-zA-Z] and continues on with [a-z]. The desired result was obtained, but partially the odd words like ( thisIsOddWordd ) were still marked as wrongly spelled.

I had asked this question before but it didn't get much attention/any-proper-solution. So I am asking again here which might be a better fit for this question.

How do I obtain the desired behavior, and what was I doing wrong?

Edit1: Along with using syn match command, another simpler way to accomplish something very, very similar is :setlocal spelloption=camel

  • Please don't edit answers into your question. Instead, post an answer of your own. You will be able to accept it after 48 hours (although this would mean un-accepting Vivian's answer). Also please clean up your question cross-posted on SO if possible,
    – Friedrich
    Commented Apr 26 at 9:39
  • 1
    Your edit would be better as an answer. spelloptions+=camel is new to me*, and I'd like to upvote it! * It's fairly new to Vim, too: it's available as of nvim 0.5.0 and vim 8.2.0953.
    – Rich
    Commented Apr 26 at 9:41
  • @Friedrich I am going to delete the question that I posted on stackoverflow site. But I will wait for a confirmation reply from you. I am still kind of new to stack sites, So I am not sure if deleting is the way to clean up things, or if there are better ways like merging. That's why I shall wait for your reply before deleting the question from SO site. Commented Apr 30 at 14:31
  • I'm a regular community member and my opinion counts only as much as anybody else's. I'm most notably not a moderator or anything special. Having said that, yes, deleting one of the duplicates would be the way to clean it up. You probably won't be able to, though, as you have an upvoted answer on SO.
    – Friedrich
    Commented Apr 30 at 14:37
  • @Friedrich So how do I delete the old question? Commented Apr 30 at 14:40

2 Answers 2


I would mark the NoSpell words:

syn match myExCapitalWords /\<\l\+\u\w*\>/ contains=@NoSpell

These marks the words that include an Uppercase letter somewhere in the middle of the word as not to be spell checked.

The original solution looks also fine the lowercase words should not match the proposed pattern. If they are excluded from spell checking I believe it is not because of the command (maybe it is part of the custom dictionary)

It would be helpful to have an example such that we can reproduce your problem.

  • Thanks, @Vivian De Smedt. It seems to work. Previously, the spellchecker used to mark acronyms as wrongly spelled. So, to include all capital words to be included for @NoSpell I modified the pattern like this: /\<\h\+\L\w*\>/ Let me add and use this line in my vimrc and if I don't see any issues in 2 days, then I will surely mark your answer as the best one. Thanks again. Commented Apr 24 at 2:18
  • Thanks for the feedback :-) If you have a counter example shared it in your question such that we can reproduce the problem and chase it ;-) Commented Apr 24 at 3:38
  • 1
    Thanks Rich :-) You are right. I have corrected the answer accordingly. Commented Apr 25 at 15:01

If not better, then at least there is a simpler method to achieve this thing(not making words like 'alexanderSupertramp' marked wrongly spelled by default).

:setlocal spelloption=camel

Using this spelloption=camel would make the sub-words like alexander or Supertram marked as wrongly spelled only if they are not dictionary words, not by default because of the oddness.

The proposed answer of Vivian De Smedt will still be useful in a slightly modified way, because acronyms will still be marked wrongly spelled. So if you want to disable spell checking in all capital letter words or any other area that you can define using a regex pattern, then you could use a command like this one:

syn match ALLCAP +\<\u\u*\>+ contains=@NoSpell

But using this command will stop spellcheckers for all capital letters words altogether. So, if you write even dictionary words(like TABLE, or CHAIR) in all capital letter and spell them wrong('TABBLE', or 'CHAIREE') they will not be marked as wrongly spelled.

A better approach would be using zg, zw' in normal mode. Generally, people like me refrain from using zgorzw` because they don't want to populate the dictionary with random acronyms or even random words. So, even better approach would be following these three steps:

  1. cd ~/.vim/spell, cp en.utf-8.add markdown-en.utf-8.add. Where you could use any file type instead of Markdown. And choose your vim configuration directory, which might be some other location.

  2. mkspell[!] markdown-en.utf-8.add it will create markdown-en.utf-8.add.spl file. And use ! if you need to replace an already existing file.

  3. Add lines like these in .vim/after/ftplugin/markdown.vim file. Remember, you can use these steps for any file type.

    let &l:spellfile='~/.vim/spell/markdown-en.utf-8.add'
  4. Instead of adding that in ~/.vim/after/ftplugin/markdown.vim file you could have added that in your vimrc like this.

    augroup markdownFile
      au BufRead,BufNewFile,BufEnter *.md,*.markdown let &l:spellfile='~/.vim/spell/markdown-en.utf-8.add'
    augroup END

So, there is a better appropriate way so that spell checker doesn't mark your acronyms wrongly spelled using zg and zw while you can feel safe that you are not populating the word-file with random random words.

Personally I am still using the syn match method but not for acronyms. In my markdown notes while using a word borrowed from other language I put that word inside *<word>*. So, I am still using syn match so that those words or even lines inside *<line/word>* doesn't get spell checked using this command.

syn match insideStar :^\|\s\*.*\*$\|\s: contains=@NoSpell

Here in the pattern, ^\|\s is making sure that the * is starting either at the beginning of the line or after white space, and $\|\s is making sure that the searched item is ending either with a whitespace or with the ending of the line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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