3

Note: this may be a Windows-only problem. The symptom has been reproduced on multiple Windows 10 machines.


I find my syntax-highlighting for Markdown files (ending in .md) will fail to rander when there are "code-blocks" of hyper length (say, multiple lines of code that runs longer than the vertical length of the monitor). This usually happened when I jump directly to the bottom of the document using G in normal mode. Here goes a comparison of the right and wrong syntax-highlighting obtained before and after the "immediate fix" (more details below).

enter image description here

To restore the correct "colorization", I originally was paging down to the bottom of the document using <c-f>. Lately, I found the following immediate fix that worked within an active Vim session.

Following this suggestion from Issues for Vim on Github, setting :syntax sync minlines=10000 in a buffer does fix the coloring problem immediately. Yet, the fix only stay within the current Vim session and dropping any of the following lines to my .vimrc did not help to reproduce the immediate solution.

:syntax sync minlines=10000k
autocmd BufEnter,BufRead *.md :syntax sync minlines=10000
set redrawtime=10000 "Suggested by someone else from the vim-Github-issue-page. Did not help in my case.

As a compromise, I am adding an abbreviation for the command line mode as the following:

cab mdd syntax sync minlines=10000

I am looking for a once-and-for-all fix to the syntax-highlighting problem with markdown files.


Please advise if I am missing some handy settings for vim. This only happened on gvim.exe installed on Windows 10 machines. I have been reusing almost 100% of the .vimrc settings across Linux, Windows-WSL and Windows machines. Unix-based Vim has been consistently getting the syntax-highlighting correct.

4
  • 2
    Not a solution but if you must resort to your compromise/workaround you can use syntax sync fromstart instead. Arbitrarily large numbers are kinda hacky.
    – B Layer
    Aug 25, 2019 at 21:38
  • 1
    @BLayer, thank you for pointing out the proper option to issue. Problem solved.
    – llinfeng
    Aug 26, 2019 at 3:44
  • 1
    No problem. Glad you got your answer. Cheers.
    – B Layer
    Aug 26, 2019 at 4:05
  • 1
    Youre not alone, OP. I get this on my (2012) macbook all the time.
    – D. Ben Knoble
    Aug 26, 2019 at 5:32

1 Answer 1

4

The issue here is ordering, you need this syntax sync command to be issued only after the syntax rules for Markdown have been loaded, otherwise the sync will be cleared as those rules are loaded.

A good way to do so is to add this syntax sync command to a syntax file in the $HOME\vimfiles\after directory (that's for Windows, the corresponding directory on Linux/Unix would be ~/.vim/after.) Unfortunately, none of the other options you mentioned will issue that command late enough to work for your case, so that's actually the type of situation in which you want to resort to using the "after" directory. (See :help vimfiles for more details.)

In your specific case, create a file $HOME\vimfiles\after\syntax\markdown.vim with the single line:

syntax sync minlines=10000

Or, as @BLayer points out in the comments, you might as well just have the syntax engine evaluate the file from the start every time (10,000 lines is close enough to that in most cases):

syntax sync fromstart

This file will get loaded after the usual Markdown syntax is loaded, so it's the perfect place to add your customizations.

1
  • 1
    Thanks a lot! Dropping syntax sync fromstart into $HOME/vimfiles/after/syntax/markdown.vim did solve the rendering problem altogether! I should have tried this after directory early on.
    – llinfeng
    Aug 26, 2019 at 3:44

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.