I'd like to edit text with markdown syntax. Searching for ways of using mixed syntax in the same file I've discovered this question with an answer saying that if I add the line let g:markdown_fenced_languages = ['c'] on my vimrc file it'd accept the c language syntax. Alternativey, there's also this question with an answer that recommends installing the vim-pandoc and vim-pandoc-syntax plugins.

In my case, none of those solutions are working... I've tried adding the line let g:markdown_fenced_languages = ['c'] on my vimrc file and opening a markdown file with a small piece of c code and the syntax was not working. Also, I use VimPlug for installing plugins, so I removed all other plugins that I had installed and added the following on my vimrc file:

call plug#begin('~/.vim/plugged')
Plug 'vim-pandoc/vim-pandoc'
Plug 'vim-pandoc/vim-pandoc-syntax'
call plug#end()

Together with installing them with :PlugInstall on a file. But that didn't work for me at all as well. Am I missing something? In my view the markdown syntax would be working as soon as I had the vim-pandoc and vim-pandoc-syntax installed... Just like it's with other plugins related to syntax on Vim.


I figured out that in order to make those solutions work I need to name the file as .markdown or, alternatively, activate it with :set ft=markdown (:argdo set ft=markdown for doing it on all files in buffer). In my case, the solution of adding the line let g:markdown_fenced_languages = ['html', 'python', 'bash=sh', 'c', 'javascript'] with all languages that I need worked better. The vim-pandoc plugin doesn't seem to highlight syntaxes correctly (I've tested the bash and c syntax).

  • 1
    .md should also work as an extension as well. If you only need the syntax, you can :setlocal syntax=markdown, but typically you want the filetype. – D. Ben Knoble May 2 at 20:25
  • 1
    That's an alternative... Actually I'm working with markdown files from TiddlyWiki. So, all the files end with .tid... In this specific case, adding the line autocmd BufEnter *.tid :setlocal filetype=markdown in my vimrc file completely solved the problem because it'll automatically see all my .tid files as .markdown files. – raylight May 2 at 20:31
  • 1
    Using BufRead is slightly better than BufEnter (because BufRead will only fire once, when the buffer is first opened, while BufEnter every time you enter that buffer), but yeah associating the extension with the type is the way to go. – filbranden May 2 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.