vimrc - how to block comment?

My solution is to wrap the code inside a function.

This works well in vimrc, e.g., for in-place heredoc syntax highlighting tests, which also require real block comments without leading characters. In my vimrc, I use such a block directly after setting up my heredoc SyntaxRanges.

function! _blockcomment()

    " free text comment
    You can write free text here,
    but vim will try to highlight it as vimscript!

    " markdown heredoc
    test <<MD
    ### Nevertheless ###
    * for testing my fuzzy SyntaxRange heredocs
    * having no leading chars is essential
    * and the blockcomment function does the trick
    MD  

endfunction 

This solution is similar to @Stéphane's if 0 trick, which did not work for me. Just make sure to never call this function!


I do not think this is possible. The best you'll be able to do is block select some text, and do a search/replace on the first character s/^/"/ in vim to insert a " to the beginning of each line.

The vim plugin NERD Commenter might help make this easier as well.