The Linux Page

gVim syntax highlighting failing? (especially for markdown highlighting)

What is a fishing boat doing in a field?!

Now a days, I write a lot of my documentation using markdown.

The fact is that it is rather difficult to find problems when I make a mistake such as put a lone backtick (`).

Often it feels like the syntax highlighter is failing.

One way to at least make sure that the file fails for real is to make sure that the highlighting starts from the very beginning of the file. To do so you want to change the number of lines that the highlighting works on.

The number of lines is defined in two variables and you probably want to change both of them. Note that to do so, you need to use the :syntax command like so:

:syntax sync minlines=100000 maxlines=100000

Feel free to change the numbers to whatever suits you. Hopefully you don't have files that are more than 100,000 lines, though.

Now, whatever you do in the file, the highlighting is going to be calculated from the start of the file. So if there is an error, you will detect it quickly and it will permanently show up.

In markdown, I noticed that having the following shows you that you have an error in your code:

under_score

The underscore can be used to italize words as in:

_italic_

As we can see, it has to appear at the start or the end of the word. When it appears inside a word, however, it shows an error on the underscore character like shown above.

To remediate and because that most certainly means this is code, you can either use the backticks:

`under_score`

or change your documentation to include that word in a code block:

    under_score (lines starts with 4+ spaces)

Here the underscore itself is not shown in red because vim considers it valid wherever it appears in code.