tcomment_vim icon indicating copy to clipboard operation
tcomment_vim copied to clipboard

Force comment type in file?

Open eirabben opened this issue 6 years ago • 4 comments

Is there any way to force a single comment type in a file?

I have a twig file like this:

{% extends '_layouts/default' %}

{% block content %}
  <section>
    <p>404</p>
    </section>
{% endblock %}

When commenting with Tcomment, it uses html style comments by default. If I set the commentstring using autocmd FileType html.twig setlocal commentstring=\{#%s#\} or call tcomment#type#Define('html.twig', '{# %s #}') it uses Twig comments on the lines that start with Twig syntax, but not on lines starting with HTML.

I would like all comments in the file to be Twig comments. Is there any way to do this?

eirabben avatar Aug 24 '18 07:08 eirabben

I would like all comments in the file to be Twig comments. Is there any way to do this?

Untested (please let me know if this doesn't work out): Is the filetype twig or twig.html? Anyway, with the current master version you should be able to set g:tcomment#filetype#guess_twig or g:tcomment#filetype#guess_twig_html to 0 in order to disable guessing the filetype.

HTH

tomtom avatar Aug 24 '18 07:08 tomtom

The filetype is html.twig. But none of these seem to work for me, neither does g:tcomment#filetype#guess_html_twig. I still get HTML comments on HTML lines and block comments with multiple lines.

I am using sheerun/vim-polyglot for the Twig syntax, if that makes a difference.

eirabben avatar Aug 24 '18 08:08 eirabben

You might also have to execute

let g:tcomment#filetype#map['html.twig'] = 'twig'

after the plugin was executed once. (I'll make it easier to customize that.)

tomtom avatar Aug 24 '18 10:08 tomtom

Ok, so this works for me:

autocmd FileType html.twig setlocal commentstring=\{#%s#\} in init.vim
Running let g:tcomment#filetype#map['html.twig'] = 'twig' after using the plugin once

Is there a way to automate execution of the plugin so it can run every time i open a Twig file?

eirabben avatar Dec 18 '18 11:12 eirabben