10

There are the "normal" straight quotes:
' "

And you have the angled "smart quotes":
‘ ’ “ ”

Vim's spellcheck works with "straight" quotes, but not angeled quotes, so this is considered "wrong":
It’s ... Monty Python’s

Even though it's not.

Screenshot, in case your font doesn't show the difference:

enter image description here

How do I fix this? I would prefer to get it working for both variants (it's and it’s).

6
$ grep "'" /usr/share/dict/words | wc -l
26226
$ grep -i python /usr/share/dict/words
Python
Python's
python
python's
pythons

The problem is that all these words with apostrophes are actually in your dictionary file. So if you're okay with modifying your vim spelling dictionary, then do so:

$ grep "'" /usr/share/dict/words | sed "s/'/’/g" >> ~/.vim/spell/en.utf-8.add

This will

  • grep to find all words in your system dictionary that contain an apostrophe (');
  • sed to change the straight quotes to smart quotes (that's s/'/’/g, where the first quote is straight and the second is smart); and
  • append it to your language dictionary (replace with whatever your language is).

You will need to recompile this to a .spl file, which you can do from Vim:

:mkspell! ~/.vim/spell/en.utf-8.add

If you want to use the actual spell files that Vim uses as a starting place (instead of your system dictionary), you can use the :spelldump command. The output will include all the words Vim uses for the current spelllang, including those already added from the .add file. Save the result of :spelldump to a file and remove the first two lines (header info), then use the same commands as above. You may also want to pipe it through uniq as well, to remove duplicate entries. (No need to sort; the output of :spelldump is already sorted.)

  • Why do you use 's as a pattern? Isn't just searching for ' correct, asl well? This will miss words that have a ' in a different location (such as you'd, you've, etc.) – Martin Tournoij Feb 5 '15 at 17:44
  • Yep, you're right. I've edited my answer. – wchargin Feb 5 '15 at 19:52
  • Thanks :-) I wasn't sure if you did that with a reason, so was hesitant to edit it myself... – Martin Tournoij Feb 5 '15 at 20:01
  • If you choose to go the :mkspell! route, you may also want to filter out words that are intended for irrelevant regions. – Aaron Massey Apr 19 '15 at 22:57
1

As of now, you can simply download and compile a new spell file for the VIM. The Unicode quotes were added to the current version of the English dictionary.

Steps, based on this article:

  1. Create directory ~/.vim/spell and change to it. (The path is part of VIM's runtimepath.)

  2. For English language, the dictionary can be downloaded here. (Alternatively: from LibreOffice repo - you need both .dic and .aff files.)

    N.B. For better results, I would recommend getting both en_US and en_GB. en_GB dictionary could be found in the LibreOffice repo.

  3. Unzip the file:

    unzip -x hunspell-en_US-2017.01.22.zip
    

    The archive must at least contain these files: en_US.aff and en_US.dic.

  4. Start VIM (in the ~/.vim/spell directory) and in VIM execute the command: :mkspell! en en_US

    Or if you have also downloaded en_GB files: :mkspell! en en_US en_GB

  5. Exit VIM, and check the files in the current directory. There should be file en.utf-8.spl created.

  6. Done!

Now, after you start VIM and activate the spell-checking for English language, it should first pick the freshly created .spl file from ~/.vim/spell which already contains support for the Unicode quotes. At least that how it worked for me.

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.