Mesagoma
Mesagoma

Reputation: 87

How do I get VIM to recognize PHP block based on <script language="php">?

For legacy reasons I'm stuck delimiting PHP code blocks via:

<script language="PHP">

as opposed to:

<?php

This is a valid way of opening a PHP block (see "Escaping from HTML on php.net"); the only problem is, that VIM interprets this as JavaScript, forcing me to execute :set ft=php each time, if I want it to highlight and indent my code according to PHP specific rules.

I could map :set ft=php to a shortcut but that's still rather inconvenient. Does anyone know of a way to automate this?

Thanks!

Upvotes: 1

Views: 456

Answers (2)

romainl
romainl

Reputation: 196546

See narrow and nrrwrgn.

Both scripts allow you to select a "region" of code, edit it in another window with whatever filetype you want and save it back to its original location.

Upvotes: 2

Conner
Conner

Reputation: 31050

If you want to just automate the file to the php filetype you can do au FileType html set ft=php if :set ft? shows html. Or you can do it by extension like au BufRead,BufNewFile *.htm set ft=php

Also, read this: Different syntax highlighting within regions of a file

Upvotes: 1

Related Questions