1

I do not mean to let vim check my spell automatically, so please do not tell me to add a autocmd ... line in my vimrc.

I created a .md file and put these contents in it:

8) good fftowndn

Then I run the command :setlocal spell! in the normal mode, but this does not check the wrong spell token of fftowndn in my contents. However, the spell checking works well if I comment the contents.

How could I make spell checking work with .md please ?

Edit: in other file types such as txt file, after I run :setlocal spell!, the error tokens of fftowndn will be highlighted but here I do not see this highlight in the markdown file.

Edit2:

I come to find that the spell checking works well for the title marked with #, ##, ..., ######, and from ####### on there will be no checking. It is the same with my markdown contents. If I do not mark my contents, there will be no spell checkings.

Edit3:
after various trying, I got to find the problem is likely to be with this line in my .vimrc:

let g:markdown_fenced_languages = [
        \ 'vim',
        \  'html',
        \  'css',
        \  'erb=eruby',
        \  'go',
        \  'java',
        \  'javascript',
        \  'js=javascript',
        \  'json=javascript',
        \  'ruby',
        \  'sass',
        \  'sql',
        \  'xml',
        \  'cpp',
        \  'python',
        \  'bash=sh',
        \  'cmake'
        \]

I just need markdown to show highlight for me code in the block between '```' and '```' pairs, but I did not expect it will affect my spell check, how could I solve this?

  • 1
    Works for me. If you move the cursor to the "8" and then press ]s, does it jump to "fftowndn"? – Ralf Dec 19 '18 at 4:57
  • 1
    Note you need setlocal spell spelllang=LANG (i may have spelt spelllang incorrectly). Can you clarify the precise contents via a code block, and describe the expected versus observed behavior? – D. Ben Knoble Dec 19 '18 at 5:01
  • @Ralf No, at least I do not see highlight of the error tokens as does in the comments. – coin cheung Dec 19 '18 at 6:41
  • 2
    Extension to my comment above: If the cursor does not move on ]s, it means that the spelling error is not detected. If the cursor would move, then it is a highlighting problem. – Ralf Dec 19 '18 at 7:15
  • @Ralf Then maybe the spelling error is not detected. Is there any configuration items in the .vimrc that may switch off the spelling of markdown contents but not its comments? – coin cheung Dec 20 '18 at 2:09
2

You have two possible workarounds:

  1. Change the order of entries in g:markdown_fenced_languages so that 'java' is mentioned before 'html'.
  2. Set the global variable java_ignore_javadoc to some value (like let java_ignore_javadoc=1)

Background:

The Java syntax file includes the HTML syntax file to do highlighting of HTML in javadoc comments. After this include, it sets syntax spell default to prevent spell checking on all texts. See here.

By disabling spell checking for "all text" it disables the spell checking for markdown text.

When the global variable java_ignore_javadoc is set (workaround 2), the java syntax does not include the html syntax file and does not reset the syntax spell setting. Then spell checking works, but special highlighting for javadoc is disabled.

By reloading the html syntax after the java syntax (workaround 1), the setting syntax spell default (from java) is again overwritten with syntax spell toplevel from the html syntax. Hence spell checking works again.

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.