2

I use this plugin for comments.

Plug 'tpope/vim-commentary'

And when I comment html code in php I get

/* <div class="our-photos"> */
/*  <h2 class="our-photos__main-title"><?php echo $main_title; ?></h2> */
/*  <?php slider_component($our_photos, 'our_photos', false, false); ?> */
/* </div> */

But I want to get this

<!--<div class="our-photos">-->
<!--<h2 class="our-photos__main-title"><?php //echo $main_title; ?></h2>-->
<!--<?php //slider_component($our_photos, 'our_photos', false, false); ?>-->
<!--</div>-->
2
  • 1
    Can you tell us what is the filetype of your file:set ft?. Could you also tell us what is commentstring of your file :set commentstring?? Commented May 5, 2022 at 12:47
  • 1
    You could also be interested to this answer Support for embedded languages Commented May 5, 2022 at 19:19

1 Answer 1

2

I believe your file type is php and your commentstring is /*%s*/ which is reasonable for php files.

To solve your problem you could temporarily change commentstring to<!--%s-->:

set commentstring='<!--%s-->'

or set the filetype to html

set ft=html

If you want to do that forever for php file you could add the following command:

setlocal commentstring='<!--%s-->'

To the vimfiles/after/ftplugin/php.vim file.

11
  • 1
    Thanks a lot, solved.
    – serii
    Commented May 6, 2022 at 13:04
  • You are welcome ;-) Commented May 6, 2022 at 13:07
  • Sorry, i just set filetype from command mode, but where is vimfiles/after/ftplugin/php.vim to do forever for php files? I cant find vimfiles directory in my system, ubuntu. Thanks.
    – serii
    Commented May 13, 2022 at 19:09
  • By vimfiles I mean ~/vimfiles if it doesn't exist you can create it. Commented May 13, 2022 at 19:11
  • Don't work for me, same after reboot the system. i.imgur.com/TEjrOOv.png I am using neovim 7.0
    – serii
    Commented May 14, 2022 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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