Ive had no luck solving these issues for quite a while now.


When writing HTML inside a string in a file with filetype=php, the HTML is not recognized (i.e., it has no highlighting or indent).


What I've tried to solve this problem

  1. I found this plugin (this plugin uses pattern matching to determine if text is in a different language), but I didn't have any luck.

    I tried testing this plugin by writing some javascript and CSS in a buffer with filetype=html, and as you can see in the second picture, javascript and CSS are highlighted and correctly indented. I am not actually sure if this was caused by the plugin. Nonetheless php is not correctly highlighted. Highlighting for these languages may have been working already.

  2. As you can see in the picture above, php_htmlInStrings is set to 1; however, this doesn't make a difference. I am using additional syntax highlighting for php; perhaps that is causing a conflict?


When writing php code in a buffer with filetype=html, valid php code within the opening(<?php) and closing(?>) tags are not highlighted or indented.

As you can see, for some reason vim highlights some keywords like class and for but those are the only two words I've found that get recognized. class and for do not get highlighted outside of the php tags, which leads me to believe that vim is aware that it is php code within the tags, but for some reason is only able to highlight those two words.

See this screenshot:


More I've tried

As you can see in picture above php_htmlInStrings is set to 1 however this doesnt make a difference. I am using additional syntax highlighting php.vim, maybe conflicting configs?

I couldn't help but think this was my php additional syntax plugin conflicting with the settings or something, so I removed the plugin and tried writing html in a php file.

Look at this picture below: obviously the highlighting looks different as expected, but when php_htmlInStrings is set to 1, you can clearly see that vim recognized the html tags, but failed to indent them properly. Weird? Anyway so the additional syntax plugin that I am using doesn't seem to be contributing to this issue.

enter image description here

Possible Solution workaround

Write a function to change filetype to one desired and bind it to a key so I can manually switch between filetypes while editing. This should be a last resort, since I really don't want to do this.

  • so i can manually switch between filetypes while editing? Changing filetype is as easy as :setf foobar. GVim even has a dropdown menu for that.
    – Matt
    Oct 23 at 6:55
  • Welcome to Vi and Vim! This Question currently has 2 questions entangled—we prefer to stick to 1 questions per Question where possible, and here I think it might be, so please consider splitting one of them into a separate Q.
    – D. Ben Knoble
    Oct 23 at 13:59
  • 1
    I've removed comments about gvim/IDEs—let's use Vi and Vim Chat instead of comments for things like that.
    – D. Ben Knoble
    Oct 23 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.