1

vim-commentary is a great plugin for commenting and uncommenting lines. However if some filetype isn't supported, as per documentation, one can do the following: (see FAQ)

autocmd FileType apache setlocal commentstring=#\ %s

Currently for markdown commenting adds %% in front of a line.

%% a comment

I want to use comment from github flavoured markdown, i.e., like this:

<!-- a comment -->

I am not getting how to change commentrstring for markdown to get the above. Any help will be appreciated.


Edit: The problem seems to originate from the plugin vimwiki, :verbose set ft? cms? says:

filetype=vimwiki
      Last set from ~/.vim/plugged/vimwiki/autoload/vimwiki/u.vim line 142
commentstring=%%%s
      Last set from ~/.vim/plugged/vimwiki/ftplugin/vimwiki.vim line 12

I am using vimwiki with markdown extension, so it changes filetypes to vimwiki. I have put the following line in .vimrc, now it works:

autocmd FileType vimwiki setlocal commentstring=<!--%s-->
  • 4
    The runtimes that come with Vim already set 'commentstring' for Markdown to use <!--%s--> comments, see here: github.com/vim/vim/blob/v8.2.0/runtime/ftplugin/… . Are you sure it's using different comments for you? Please edit the question to also post the output of :verbose set ft? cms? , that should help us debug your issue. – filbranden Sep 22 at 9:31
  • 1
    Edited. It works now. Thanks! But it's weird that vimwiki changes the filetype all together. – Mahbub Alam Sep 22 at 14:24
1

So the specific issue you've been having is caused by Vimwiki taking over the Markdown file type globally. You have a few options to prevent Vimwiki from doing that, which should help you solve your issue.

First, you could set the g:vimwiki_global_ext variable to 0, disabling it from hooking into files anywhere with those specific extensions. You can do so by adding this to your vimrc file:

let g:vimwiki_global_ext = 0

This means temporary wikis will not be created on the fly anymore, so you'll need to use the g:vimwiki_list variable to register the locations where you want Vimwiki to be activated. This should be straightforward if you're mainly using Vimwiki to manage a single wiki or a handful of them and you don't tend to create new ones, but rather add more contents to the ones you have.

The other option you have is to use a different set of extensions for Vimwiki that doesn't clash with the usual Markdown types. For example, you could use something like *.wiki or *.vimwiki. In order to configure that, you need to set the g:vimwiki_ext2syntax variable. You set it to a Dictionary which maps specific extensions to the Vimwiki syntax type you would like to associate with that extension. (You can use 'markdown' for the default, or 'media' for MediaWiki syntax.)

Either option should help fix the issue for you. If you don't plan to create Vimwikis on the fly, go with the former. If, on the other hand, you would like to be able to create them dynamically, but on the other hand you're fine with using a file extension different from the default ones, then go with the latter.

| improve this answer | |
  • 1
    I don't plan to create vimwikis on the fly, so I decided to go with the first one. But I have run into another problem, due to plugins: vim-pandoc and vim-pandoc-syntax. Now :verbose set ft? shows filetype=pandoc Last set from ~/.vim/plugged/vim-pandoc/ftdetect/pandoc.vim line 5. So I decided to change it by adding let g:pandoc#filetypes#pandoc_markdown = 0 to .vimrc. But still set ft? shows pandoc. – Mahbub Alam Sep 22 at 18:09
  • 1
    The problem is basic markdown stuff doesn't work with pandoc filetype, like: lists (I have to add - or 2. manually for every new list entry) – Mahbub Alam Sep 22 at 18:10
  • 1
    @MahbubAlam Make sure you don't have some kind of "sessions" plug-ins making your pandoc rules "stick" even though you reconfigured the global variable that should prevent them from being set... Is that possible that this is what's causing it now? – filbranden Sep 22 at 18:17
  • By "sessions" plugin do you mean mappings will stay throughout my vim session? Then I don't think I have any "sessions" plugin. I did quit vim completely, and then open again, still same problem. – Mahbub Alam Sep 22 at 18:49
  • 1

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.