vim - using snipmate and ragtag together - php

I am trying to switch to vim for all my editing and trying out the plugins. I have been using snipmate and ragtag and like them both. Now I am coding PHP with HTML in it and I saw this question to get snipmate to work with snippets for the two file types here: Vim - Activiting HTML snippets on PHP files .
This works well, I can get snippets for both PHP and HTML, but ragtag is no longer introducing PHP <?php ... ?> blocks, it's introducing <% ... %>. Is there a way to fix this?
Thank you.

It's possible that Ragtag doesn't understand multiple filetypes. Does it work when you :set ft=php or :set ft=html.php ?
I've never used ragtag, but since you are using Snipmate too why don't you just type php<Tab>?
It's certainly a lot easier to remember and more "mnemonic" than <C-X>_ (if I read the doc well).
-- EDIT --
It appears a check is made on ft (filetype) at line 71 but it accepts only "php" as value, since you have set ft=php.html ragtag should accept "php.html" as well.
I think changing this line from
if &ft == "php"
to
if &ft == "php" || &ft == "php.html"
should work.

Related

How to correctly make conditions in TinyButStrong?

I have to make a template in the TinyButStrong language, but I have no access to the PHP side. I'm just able to modify my template and to upload it on my ERP.
Anyway, the PHP side is working well.
I tried to put an if statement in my ODT template file, but when rendering it doesn't work.
My condition:
[if [tab.product_type]!=1; then ‘[tab.product_ref]’; else ‘0’; block=table:table-row]
I verified value of tab.product_type, and the value is 0 or 1.
I tried many syntaxes, but none is working well. The only thing that it shows is:
.
Where did I make a mistake? I really don't understand, because I tried many syntaxes and I still get this line.
Little update :
I saw that the "when" is more adapted to this usage.
I found a syntax but I'm still having bad results. I made this :
[tab.product_ref;block=table:table-row;when [tab.product_type]!=1]
Anyway, it's giving me lines where tab.product_type is 1.
Why ?? I really don't understand how this language works...

Is it possible to comment out a line of mixed syntax code (PHP + HTML) with a single keybind?

When I comment out a line of strictly PHP code using my keybind (ctrl+/), the entire line is commented out and becomes grey in color, as desired. The same is true for a line of strictly HTML code. But if execute the same keybind on a line that is a mix of HTML and PHP code, e.g.
<img width="<alt="<?php echo esc_attr( $spacious_slider_title ); ?>">
the entire line does not become grey in color. Only the HTML portions of the line become grey (screenshot example). Plus, in that case, I believe the PHP code will still execute. Is there a way to completely comment out a line of mixed syntax code like this, ensure the PHP code does not execute, and have the line completely greyed out in VS Code, with a single keystroke? If so, how would I approach that?
My current course of action in these cases is to carry out the comment keybind, which wraps the line in HTML comments. After, I will manually add a // before the PHP code to also comment it out. I'm hoping there is a single keybind solution to this, as this sometimes becomes tedious.
I should perhaps note that I just installed VS Code and am learning it. I am coming from SublimeText, so the first thing I did was install SublimeText keybinds. This was an issue with SublimText as well, and I don't believe there was a solution.
I've seen this previous question (How to comment out both HTML and PHP in PHP inside HTML?). While it is related, it doesn't exactly answer my particular question about a VS Code keybind.

How to properly use language format in Notepad ++

I have this situation trying to disable a sequence into a .php file (the black commented lines, back-to-top text button);
I've read about block commenting in notepad ++ and setting the language of the file but the comment it looks like is not implemented properly.
What I've done :
-File / Open the .php file,
(already it looks like it is viewed in php language judging by the colors)
-Selection between 355-359 lines and Block Comment (ctrl+shift+Q).After that, I've added the text but it doesn't look like the other existing comments.
Any thoughts? Thanks,
PHP comments only work when you are inside PHP mode (between <?php and ?>).
When you are outputting HTML, you need HTML comments which take the form <!-- comment which does not include two adjacent hyphens -->.
The PHP within an HTML comment will still execute and the results will be output to the browser. It looks like your PHP only outputs data and doesn't do any significant processing, so that will probably be sufficient. You might, especially in other cases, be better off simply deleting the code and then restoring it from your version control system's history later.
For that part of code you should comment using:
<!-- your comment -->
As you are using html (you closed the part of your php code by ?> )

Vim add '*' character for docs on new line [duplicate]

This question already has an answer here:
How can I get Vim to not break DocBlock comments?
(1 answer)
Closed 9 years ago.
I don't even know how to search for this on google, I tried with the title of this question, but could not find anything useful.
Working with PHP on Vim, if I have something like this:
/**
* <cursor>
*/
If I press enter, I'll get:
/**
*
<cursor>
*/
What I want is this:
/**
*
* <cursor>
*/
Yes, it is just one character, but it is bugging me a little bit.
What is the easiest way to achieve this?
Edit:
My .vimrc file have these commands (and others):
" Enable syntax highlight
syntax on
" Syntax in a plugin-based way
filetype on
" Indentation in a plugin-based way
filetype indent plugin on
set fo+=or
I guess, what you need below lines in your vimrc:
filetype on
filetype indent plugin on
I'm using the configuration of spf13-vim and it works for me. I think that the plugin PHP Integration environment for Vim - PIV makes the trick because have a feature for documentation
conforming documentation blocks for your PHP code.
Well, I'm sorry for this. I found the problem:
autocmd FileType php,phtml :set ft=php.html
I used this line to load HTML snippets for PHP files with the snipMate.vim plugin. Turns out, if I remove this line, the behaviour will be what I expected to be.
Thank you everyone.

VIM: Show PHP function / class in command line?

Is there any way to show the current PHP function or class name in the VIM command line? I found a plugin for showing C function names in the status line but it does not work for PHP and in any case I prefer the command line be used to save valuable vertical lines.
Thanks.
EDIT
While looking for something completely unrelated in TagList's help I've just found these two functions:
Tlist_Get_Tagname_By_Line()
Tlist_Get_Tag_Prototype_By_Line()
Adding this in my statusbar works beautifully:
%{Tlist_Get_Tagname_By_Line()}
Also, did you read the Vim Wiki? It has a bunch of tips trying to adress the same need. There is also this (untested) plugin.
ENDEDIT
If you are short on vertical space maybe you won't mind using a bit of horizontal space?
TagList and TagBar both show a vertical list of the tags used in the current buffer (and other opened documents in TagList's case) that you can use to navigate your code.
However, I'm not particularly a fan of having all sorts of informations (list of files, VCS status, list of tags, list of buffers/tabs…) displayed at all times: being able to read the name of the function you are in is only useful when you actually need to know it, otherwise it's clutter. Vim's own [{ followed by <C-o> are enough for me.
I don't know anything about PHP, and I'm not trying to step on anyone's toes, but having looked at some PHP code I came up with this function which I think takes a simpler approach than the plugins that have been mentioned.
My assumpmtion is that PHP functions are declared using the syntax function MyFunction(){} and classes declared using class MyClass{} (possibly preceded by public). The following function searches backwards from the cursor position to find the most recently declared class or function (and sets startline). Then we search forward for the first {, and find the matching }, setting endline. If the starting cursor line is inbetween startline and endline, we return the startline text. Otherwise we return an empty string.
function! PHP_Cursor_Position()
let pos = getpos(".")
let curline = pos[1]
let win = winsaveview()
let decl = ""
let startline = search('^\s*\(public\)\=\s*\(function\|class\)\s*\w\+','cbW')
call search('{','cW')
sil exe "normal %"
let endline = line(".")
if curline >= startline && curline <= endline
let decl = getline(startline)
endif
call cursor(pos)
call winrestview(win)
return decl
endfunction
set statusline=%{PHP_Cursor_Position()}
Because it returns nothing when it is outside a function/class, it does not display erroneous code on the statusline, as the suggested plugin does.
Of course, I may well be oversimplifying the problem, in which case ignore me, but this seems like a sensible approach.

Categories