tpope / vim-commentary

commentary.vim: comment stuff out
http://www.vim.org/scripts/script.php?script_id=3695
5.9k stars 214 forks source link

Comments for html and markdown #90

Closed rpietro closed 6 years ago

rpietro commented 7 years ago

Hi, I've trying to find a way to add single and multiline comments for html and markdown. For example:

<!-- foo -->

<!-- 
foo
bar 
-->

when I try to comment I can only get a '>' symbol in front of the line, even if the syntax is set to markdown on html

any thoughts on what I might be doing wrong?

tpope commented 7 years ago

Check :verbose set commentstring?

azoimide commented 6 years ago

@rpietro I had a similar problem, when I ran verbose set commentstring? I got commentstring=> %s.

I moved my line autocmd FileType markdown setlocal commentstring=<!--\ %s\ --> to the end of my .vimrc file and suddenly I got commentstring=<!-- %s -->.

My commentstring command for MATLAB worked just fine before the move, and I don't know why it works for markdown now, but maybe this works for you as well! :)

tpope commented 6 years ago

The problem is that is that autocommands run in the order they are defined, so if you define your autocommand before filetype on, the filetype plugin will override your autocommand. The only 100% surefire way to avoid ordering issues is to use "after" runtime files, e.g. ~/.vim/after/ftplugin/markdown.vim. But I hate having a bunch of tiny files, so I generally just arrange my vimrc correctly and hope filetype off|filetype on doesn't get called during runtime.

azoimide commented 6 years ago

Ah, I had indeed filetype on after the commentstring commands! But MATLAB didn't need the filetype on, but it did need the commentstring command... Anyways, thanks for the explanation!

albertnetymk commented 4 years ago

I saw that commentstring=>\ %s is in markdown.vim bundled with neovim. If I understand it correctly, this actually creates a "block quote" not commenting. Why so, instead of sth like commentstring=<!--\ %s\ --> shown above?