markdownneovimtreesitter

Neovim: no syntax highlighting with treesitter for markdown


It actually works with the Kickstart setup, but stops working as soon as I change the coloscheme to anything else. None of the color schemes that came with the AppImage distribution seem to highlight neither simple Markdown, nor the Hugo-style Markdown with YAML "front matter".

When I set additional_vim_regex_highlighting = true, everything is highlighted as expected, but that means two things are doing the same job. Removing treesitter altogether also works, but the highlighting for other things is not as detailed.

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1692716794

Output of :checkhealth nvim-treesitter:

nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- WARNING `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
- WARNING `node` executable not found (only needed for :TSInstallFromGrammar, not required for :TSInstall)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (SUSE Linux) 7.5.0
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "x86_64",
  release = "5.14.21-150400.24.100-default",
  sysname = "Linux",
  version = "#1 SMP PREEMPT_DYNAMIC Mon Dec 4 19:12:13 UTC 2023 (3f5cd84)"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - dockerfile          ✓ . . . ✓
  - elixir              ✓ ✓ ✓ ✓ ✓
  - gitignore           ✓ . . . .
  - go                  ✓ ✓ ✓ ✓ ✓
  - gomod               ✓ . . . ✓
  - gosum               ✓ . . . .
  - gotmpl              ✓ . . . ✓
  - gowork              ✓ . . . ✓
  - heex                ✓ ✓ ✓ ✓ ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - json                ✓ ✓ ✓ ✓ .
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - yaml                ✓ ✓ ✓ ✓ ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang} ~

I'm not quite sure where the problem lies. Is it parser? A color scheme? If it is anything to do with color scheme, is there a list of the ones supported by treesitter?


Solution

  • A crude solution to the issue is to create an after/ftplugin/markdown.lua file. In that file, among other things specific to this file type, add

    vim.cmd('TSDisable highlight')
    

    Neovim will now resort to its own regex highlighting for Markdown files only, which is fairly sufficient to my taste. The rest of the file types will have Treesitter features.

    A side note: ftplugin is just a directory, one doesn't have to install any plugin by that name explicitly.