2

I have the annoying issue that I have a .php file with HTML, CSS, Javascript and PHP. I use Vim. But the autoindent is always messed up and only works for one language in the whole file. Is there a vim-plugin which detects what language I am writing (by looking at the <style>, <script>, and <?php tags maybe?) and indent in the right way with the right syntax color and stuff?

1 Answer 1

1

According to Vim syntax documentation, you can define blocks of syntax:

syntax include @PHP syntax/php.vim
syntax include @CSS syntax/css.vim
syntax include @JS syntax/javascript.vim
syntax include @HTML syntax/html.vim
syntax region PHP  start=+<?php+ keepend end=+?>+  contains=@PHP
syntax region CSS  start=+<style>+ keepend end=+</style>+  contains=@PHP
syntax region JS  start=+<script>+ keepend end=+</script>+  contains=@PHP
syntax region HTML  start=+<html>+ keepend end=+</html>+  contains=@PHP

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.