How do I get VIM to recognize PHP block based on – Mesagoma Jul 18 '12 at 03:02

2 Answers2

2

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.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • Maybe I'm missing something but wouldn't this be roughly on the same level as having to execute `:set ft=php`? If I understand correctly, using `narrow`, `nrrwrgn` and `:set ft=php` would all result in the desired filetype but they are all manual and would have to be applied for each file... Thanks for the suggestion, though! – Mesagoma Jul 18 '12 at 15:26
  • It is the same thing but applied to a region instead of the whole buffer. What you really need are two customized syntax files (one for HTML and one for PHP). I doubt anybody here will take the time and effort to write these for you as it's not a particularly trivial task and probably too specific and rare. In the mean time, you could have a look at `:help syntax` and see if you can adapt your existing syntax files to your need. – romainl Jul 18 '12 at 15:53
  • As you suggested, I had a look at my syntax files and realized that I would also have to adjust the indent, code-complete and filetype files making adjustments to both HTML and PHP related files to achieve complete support for ` – Mesagoma Jul 18 '12 at 23:35
  • May I ask why you use this particular construction? I've been doing PHP on and off for about 6 years and I've never come accross ` – romainl Jul 19 '12 at 05:52
  • There's an old external tool that we use to edit some pages which has the annoying habit of scanning files and "correcting" HTML files. Unfortunately, it doesn't understand `` blocks alone; this situation has little to do with poor programming, it's simply legacy. We're in the process of migrating the site to a CMS, which will put an end to this. – Mesagoma Jul 19 '12 at 21:25
1

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

Conner
  • 30,144
  • 8
  • 52
  • 73
  • Thanks for your response! I use .php and .htm file extensions and in each case I need to use the ` – Mesagoma Jul 18 '12 at 03:12
  • I also looked at the page you referred to but am still trying to figure out how to apply this info for my purposes, especially given how the method provided there supposedly won't work on files that VIM already assigns a filetype to by default. I'm also looking at [VIM syntax highlighting of html nested in yaml](http://stackoverflow.com/questions/4829666/vim-syntax-highlighting-of-html-nested-in-yaml) in this context. – Mesagoma Jul 18 '12 at 03:23