When I work on PHP files, there are many chances that I will embed some HTML into it. The problem is when I edit a file named foo.php
Vim automatically sets its filetype to php and the snippets for html doensn't work in it.
Well I can quickly set the filetype to html (:set ft=html
) but changing between two seems hard to me and I lose the highlightation of php file if I set it to html, its amazing that highlightation for html works if the filetype is php.
I'm using snipMate as my snippet manager. How can I achieve which I want.
It is easy for PHP and HTML condition (and if you use snipMate), I haven't tried on other filetypes. You can set this in you ~/.vimrc file:
autocmd filetype php set filetype=php.html
Point to be noted is when you set the filetype to php.html
, the highlightation is for PHP and the snippet will be imported from html. The above configuration will be not same to set ft=html.php
(well the snippets will work) because the highlightation will be enabled for html, and as we know php prettifies html but html doesn't prettifies php. In same manner if you do set filetype=php.css.html
the snippets for all three filetypes will be imported but the vim will highlight according to PHP.
You didn't tell us the snippet plugin you're using. For the original snipMate plugin, create a file ~/.vim/ftplugin/php_snipMate.vim
with the following contents:
silent call ExtractSnipsFile(g:snippets_dir . 'html.snippets', &l:filetype)
Because of the script name and location, it will be automatically sourced for all PHP files and import the html snippets in addition to all existing PHP snippets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With