Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim markdown syntax highlighting is very buggy

I'm not sure which markdown plugin I'm using, but it's not doing a great job of parsing this README.md file.

Here's a visual of what's going on: enter image description here

Not sure why it's highlighting everything after an underscore, highlights generally mean italic words. It's not very pleasent working in this way. By the way, I've posted the exact code here to demonstrate that the italics are not actually taking place after the underscore.

payment_address
POST
  currency      string      ex: "BTC"
  amount        int         ex: 100000
 *timeout       int         ex: 600
 *callback      JSON object
    method      string      ex: "HTTP_POST", "BLOCKCHAIN_WRITE"

    params      JSON object
      HTTP_POST PARAMS:
      url       string      ex: "http://florincoin.info/mucua/callback/
      data      string      ex: see below

The payment_address api is by far the most

Note: stackoverflow.com doesn't turn #### payment_address into a H3, but it also doesn't make the _address part italic.

  • Is this a bug in vim or am I doing something wrong?
  • How can I find out which vim plugin I'm using to issue a bug report / pull request for a fix?
like image 771
Joey Avatar asked Jul 13 '14 04:07

Joey


People also ask

How do I permanently enable syntax highlighting in vim?

Add the text, “syntax on” anywhere in the file to enable syntax highlighting permanently for vim editor. Save and close the file by typing ':x'. For disabling the feature, just re-open . vimrc file, change the text “syntax on” to “syntax off” and save the file.

Does vim support syntax highlighting?

Syntax highlighting enables Vim to show parts of the text in another font or color. Those parts can be specific keywords or text matching a pattern. Vim doesn't parse the whole file (to keep it fast), so the highlighting has its limitations.

How do you highlight code in markdown?

To highlight code, write the name of the language the code is written in after the initial triple backticks. In the above example, the code is written in JavaScript, and hence javascript is added after triple backticks.


3 Answers

This is because in markdown underscores mean italics, and that's what Vim is showing. Vim just renders italics in a weird way.

What you are expecting is a Github extension.

You can install this plugin to enable Github Flavored Markdown highlighting.

like image 143
esneider Avatar answered Oct 05 '22 03:10

esneider


This is not an exact solution to your syntax highlighting issue but rather a solid way to debug VIM issues. Please don't mark this as the solution to your question.

I would manually go through your ~/.vim/bundles/ folder and mv each plugin out one by one until you find the culprit. Start with the plugins that are likely to be causing the problem and continue from there. I.e, vim-markdown is more likely to be causing these issues than wap-it (my VIM plugin ;) ).

If you still haven't found the culprit after moving all your plugins out, I would then ensure that you're running the latest version of VIM. If THAT doesn't work, I personally would try reinstalling but I'm also not very well versed regarding VIM's internals.

Hope this helps,

like image 26
muffs Avatar answered Oct 05 '22 05:10

muffs


The solution I found was to escape underscores in my markdown code. It doesn't make a difference to github whether or not the underscores are escaped, but I suppose for compatibility reasons it's good to escape them anyway (it also solves the problem of incorrectly highlighted text in vim).

Update: This solution doesn't work when underscores are escaped in code spans. Here's an example:

Markdown code:

`HELLO\_WORLD`

Output:

HELLO\_WORLD

like image 21
Joey Avatar answered Oct 05 '22 05:10

Joey