Better support for HTML syntax inside of PHP files
As part of my day job I have to do a lot of editing of HTML inside of .php files (CodeIgniter views, WordPress, etc) and it's a pain to do this in Vim by default, usually I change syntax with :set ft=html and similarly for PHP when I need to, but this gets a bit dull. One of the people I work with, who uses Vim but without Janus, uses this plugin: http://www.vim.org/scripts/script.php?script_id=604 to fix this for him and it looks to do a good job.
I've put that file into ~/.janus but it wasn't being loaded, so I tried putting it into ~/.janus/indent and that still hasn't helped at all, nothing's changed - am I missing something really obvious?
On another note, I'd say this is a fairly popular issue, something worth considering including in the default Janus build?
Thanks :)
Hey Jack,
I'll add the plugin later tonight, if I did not get any obvious errors I'll push it...
Wael
Wael Nasreddine Sent from my iPhone
On Mar 1, 2012, at 23:27, Jack Franklin [email protected] wrote:
As part of my day job I have to do a lot of editing of HTML inside of .php files (CodeIgniter views, WordPress, etc) and it's a pain to do this in Vim by default, usually I change syntax with
:set ft=htmland similarly for PHP when I need to, but this gets a bit dull. One of the people I work with, who uses Vim but without Janus, uses this plugin: http://www.vim.org/scripts/script.php?script_id=604 to fix this for him and it looks to do a good job.I've put that file into
~/.janusbut it wasn't being loaded, so I tried putting it into~/.janus/indentand that seems to have done the trick - I'm just wondering if something like this is worth including by default in the regular Janus build? I imagine it's a common issue, especially amongst people who work a lot with PHP frameworks or CMS' like CodeIgniter or WordPress.
Reply to this email directly or view it on GitHub: https://github.com/carlhuda/janus/issues/411
That would be great, or just instructions for me on how I can add it myself would be great, there may well be better solutions out there but this seemed one of the more popular ones, it appears a few times on StackOverflow too.
Edit - I also found this one: http://vim.wikia.com/wiki/Better_indent_support_for_php_with_html, but again I'm at a loss as to how to add them myself to janus through the ~/.janus folder. If someone would mind helping me out with that, I'm happy to test both the solutions & report back if the general consensus is that something like this in Janus would be beneficial.
A Wiki page of the below comment would be highly appreciated, because unlike us, you will fall into traps and this might make a more comprehensive wiki page..
There's 2 methods for adding a custom plugin
First method
Well this is the easiest, if you don't care about keeping submodules organized in a git repositories as submodules, this will be your choice, however you should know that, having 1 or 2 scripts is fine, but you really gonna hate this if you have > 20 plugins and wanted to update them.
To be able to use the ~/.janus folder, you have to understand how it works first, the janus folder is considered by pathogen (which Janus uses to load all these unusual, in vim terms, folders) the bundle folder, and it expects it structured as so:
$ tree .janus
.janus
|-- php-enhanced-html
| |-- indent
| | `-- php.vim
|-- something
| `-- plugin
| `-- something.vim
`-- some_other_plugin
`-- autoload
`-- some_other_plugin.vim
So as you can see, each plugin has to be in it's own folder, otherwise it won't work, so going back to our PHP plugin, since it's only a PHP file you have to create the structure yourself, and since it's an indent plugin, it should be in the indent folder so go ahead
mkdir -p ~/.janus/php/indent
cd ~/.janus/php/indent
curl -o php.vim 'http://www.vim.org/scripts/download_script.php?src_id=2863'
That should do it
Second Method (Recommanded)
This one is very useful if you would like to keep your janus folder organized as submodules, so first, we need to find a git repository for that script, all and I mean all vim scripts are available as a git repository right here on github, at https://github.com/vim-scripts, so finding the plugin is an easy task, Google will help you do that, search for site:github.com http://www.vim.org/scripts/script.php?script_id=604 where the given url is simply the URL of the script, and you'll find the repo here
so to add it, this is the easy part
mkdir -p ~/.janus
cd ~/.janus
git init
git submodule add https://github.com/vim-scripts/php.vim-html-enhanced.git php.vim-html-enhanced
git commit -m 'I added php.vim-html-enhanced'
and that's really it, Janus will find it this way
Hope that helps and please let me know which is better, because unfortunately, I do get to work with PHP sometimes and I agree, the weird indentation drives me crazy..
Wael
That's awesome, thank you so much. I'll report back on my findings - I also think it would be so valuable to convert that comment into a page on the Wiki.
Exactly, but sometimes it takes me a while to get things done on my own as my time is very limited these days, so if you have some time to spare, it would be appreciated (but I think you should follow it first to make sure you are familiar with the process and I didn't make any mistakes
Update on this, I found the plugin here to be the better one: https://github.com/vim-scripts/php.vim-html-enhanced
However, there's one thing that bugged me for ages before I figured it out, and that is that in the php.vim file it has the line:
set sw=3
And I spent ages wondering why Vim was indenting 3 spaces all of a sudden, changing this to two manually in the file seems to have done the trick and now it's perfect, so if you make the decision to add this to Janus, it might be worth changing it to 2 or figuring out a way for it to auto detect the width (this is beyond my abilities with Vim plugins).