3
votes

I'm using Vim 8.0 and the default syntax/markdown.vim that comes with it, which is the 2016-08-20 version of Tim Pope's vim-markdown package.

This package has a bug that really annoys me on certain files: it considers any line indended by four or more spaces as a code block, including list continuations. Thus, in the following:

1. Agenda Item 1: Frob the Bazzit
   - The bazzit is something that makes us have
     very _short_ lines indeed.
   - Further frobbing is necessary

The line very _short_ lines indeed will be highlighted as a code block and the word short will not be italicised.

I'm happy with just completely disabling code block highlighting, at least in these circumstances, but I can't figure out how to do that after the fact. I've been testing with a ~/.vim/after/syntax/markdown.vim to tweak configuration, but I can't figure out how, once the

syn region markdownCodeBlock start="    \|\t" end="$" contained

has been executed in the system markdown.vim I can disable that in my after/syntax/markdown.vim. How do I do this?

(I have tried using highlight link markdownCodeBlock NONE, which does disable the code block colour on those lines, but unfortunately they are still marked as code block regions and still do not highlight any other markup in there, such as _italic_ or `code` inline markup.)

2
I edited my answer with a solution which covers I'm happy with just completely disabling code block highlighting, at least in these circumstances - padawin
I played more with it, for a less obtrusive solution than the one in my answer and had a look at the system's markdown.vim (from tpope). Based on that created the following PR: github.com/tpope/vim-markdown/pull/140. To see if it will be accepted or not ¯_(ツ)_/¯ - padawin
@padawin Yes, I was thinking the other day that maybe it should be checking for a blank line before code blocks, but had little idea how to do it. I've added your changed version after a syntax clear markdownCodeBlock in my ~/.vim/after/(None so far.)syntax/markdown.vim and will see if I find any issues with it. In the meantime, you should expand your comment above and the patch into a new answer. - cjs

2 Answers

4
votes

It looks like what you want to do is clear that particular syntax group:

To clean up specific syntax groups for the current buffer:

:syntax clear {group-name} ..

This removes all patterns and keywords for {group-name}.

But it looks like you can't clear specific definitions of a group. Just the entire group:

:syn clear markdownCodeBlock
2
votes

A wild guess, to be combined with @muru's answer, but maybe you can create a custom multi line group, called for example NoSyntax, which would be as a comment (So that when compiling the .md to pdf or other, it's ignored), something like:

[//]: # (IGNORE)
    - The bazzit is something that makes us have
      very _short_ lines indeed.
    - Further frobbing is necessary
[//]: # (ENDIGNORE)

And then use in ~/.vim/after/markdown.vim:

syntax clear NoSyntax

I am not at my computer right now to see how a group like that could be created, but as soon as I am, I'll have a play with it to see what's possible (if it is possible).

EDIT: Here is a solution which highlights a block as "Normal" (so no italic for example, but at least no code, which can answer I'm happy with just completely disabling code block highlighting, at least in these circumstances):

Place the following code before setting your colorscheme:

function! MyMarkdownHighlights() abort
    syntax region mdIgnore  start=+^\s*\[//\]: # (IGNORE)$+ end=+^\s*\[//\]: # (ENDIGNORE)$+ keepend excludenl
    highlight def link mdIgnore Normal
endfunction

augroup MyColors
    autocmd!
    autocmd BufEnter *.md call MyMarkdownHighlights()
augroup END

And use it with the comment:

[//]: # (IGNORE)

and

[//]: # (ENDIGNORE)

Here is an example (look at where my cursor is and the highlight group associated at the bottom of the screen):

enter image description here