I'm using PHP in some HAML templates, so I've got a lot of <?php echo ...?> going on. Vim is highlighting all the greater-than signs with the ErrorMsg highlighting group, but it gets quite annoying, as you can see:
What's the best way to disable this for HAML templates?
If all else fails, you could forcibly remove the highlighting for angle brackets with these commands:
:syn match Normal '<'
:syn match Normal '>'
You can change the syntax highlighting for specific file types in vim. So for .haml files put something in your .vimrc like:
au BufNewFile,BufRead *.haml set filetype=haml
then make a haml.vim file in your home/.vim/ folder.
Also check out this link
Related
I am getting this error:
Getting Warning - Cannot modify header information
I'm 99% sure it's because of a file ending with ?> and then some white space after that.
My problem is, I have looked at 15 possible files, but there are hundreds more to check. Is there an easy linux command to find the files ending with ?> and some whitespace after it? Or perhaps is there another way you guys solve this?
You are facing a EOF problem.
The whitespace at the end of the file its breaking your program, you need to find all the end of file occurrences with ?>(whitespace).
You can use a regex expression with a project finder tool, the regex would be: (?> )\z.
The \z regex condition will look for ?>(whitespace) only in the EOF.
I recommend you Sublime text 3 because you can apply regex doing a search and replace, there's a Sublime text find & replace examples if you want to learn how to.
Question: Can someone tell me where to add, in Notepad++, syntax highlighting for built-in functions in PHP?
There are a few built-in functions in PHP that Notepad++ does not highlight. One I have noticed is "real_escape_string."
The langs.model.xml file includes the words to be highlighted with the languages supported by Notepad++.
The langs.model.xml file is found at
C:\Program Files\Notepad++\langs.model.xml
At the top of that file it says the following:
"The key words of the supported languages, don't touch them!"
I edited the file anyway. I included "real_escape_string" within keywords in the PHP section. It did not work. The real_escape_string function was not highlighted.
I cannot find a way to add syntax highlighting for built-in functions from the user interface.
Under "Settings -> Preferences" I have looked at all the options and there is no option to edit syntax highlighting
Under "Settings -> Style Configurator" there's no place to edit syntax highlighting
Thank you in advance.
%appdata%/Roaming/Notepad++/langs.xml
Keywords for PHP are located around line 172
Add the keywords that you wish to highlight between the <keywords> <keywords?> tags then restart notepad++
Hey I was looking around online and couldn't find anything about how to modify the syntax highlighting rules. I am trying to add a rule for PHP variables inside of double quoted strings. In Aptana they have a rule where these variables are highlighted which I find extremely useful as I do a lot with PHP vars inside double quoted strings. This is similar to the <<
I would also like to be able to specify sets of rules, for instance on heredocs:
<<<HTML
<html>
<div>$phpvar</div>
</html>
HTML
I want The html highlighted as HTML for specifically <<
Anyone know how to customized / edit the rules for the syntax highlighting?
Go into settings
File > Default Settings
There you can select how your code is formatted wrapped etc.
For colors go to:
Preferences > Editor (under IDE settings) > Colors & Fonts
There you can play around with colors, highlighting, background, fonts etc
I need to match all three types of comments that PHP might have:
# Single line comment
// Single line comment
/* Multi-line comments */
/**
* And all of its possible variations
*/
Something I should mention: I am doing this in order to be able to recognize if a PHP closing tag (?>) is inside a comment or not. If it is then ignore it, and if not then make it count as one. This is going to be used inside an XML document in order to improve Sublime Text's recognition of the closing tag (because it's driving me nuts!). I tried to achieve this a couple of hours, but I wasn't able. How can I translate for it to work with XML?
So if you could also include the if-then-else login I would really appreciate it. BTW, I really need it to be in pure regular expression expression, no language features or anything. :)
Like Eicon reminded me, I need all of them to be able to match at the start of the line, or at the end of a piece of code, so I also need the following with all of them:
<?php
echo 'something'; # this is a comment
?>
Parsing a programming language seems too much for regexes to do. You should probably look for a PHP parser.
But these would be the regexes you are looking for. I assume for all of them that you use the DOTALL or SINGLELINE option (although the first two would work without it as well):
~#[^\r\n]*~
~//[^\r\n]*~
~/\*.*?\*/~s
Note that any of these will cause problems, if the comment-delimiting characters appear in a string or somewhere else, where they do not actually open a comment.
You can also combine all of these into one regex:
~(?:#|//)[^\r\n]*|/\*.*?\*/~s
If you use some tool or language that does not require delimiters (like Java or C#), remove those ~. In this case you will also have to apply the DOTALL option differently. But without knowing where you are going to use this, I cannot tell you how.
If you cannot/do not want to set the DOTALL option, this would be equivalent (I also left out the delimiters to give an example):
(?:#|//)[^\r\n]*|/\*[\s\S]*?\*/
See here for a working demo.
Now if you also want to capture the contents of the comments in a group, then you could do this
(?|(?:#|//)([^\r\n]*)|/\*([\s\S]*?)\*/)
Regardless of the type of comment, the comments content (without the syntax delimiters) will be found in capture 1.
Another working demo.
Single-line comments
singleLineComment = /'[^']*'|"[^"]*"|((?:#|\/\/).*$)/gm
With this regex you have to replace (or remove) everything that was captured by ((?:#|\/\/).*$). This regex will ignore contents of strings that would look like comments (e.g. $x = "You are the #1"; or $y = "You can start comments with // or # in PHP, but I'm a code string";)
Multiline comments
multilineComment = /^\s*\/\*\*?[^!][.\s\t\S\n\r]*?\*\//gm
I noticed that the syntax/php.vim file on my ubuntu machine has a php_htmlInStrings option. I can turn this option on to display HTML syntax highlighting within strings in my php files, which is great. I would also like to do javascript syntax highlighting within strings in a php file. Does anybody know if this can be done and if so how can I do it?
edited - added extra possibilities
I should also mention that I would be happy with a solution where i have to parse all my javascript strings though a php function before outputting the result. This might get around the problem suggested by conner below where vim has trouble deciding if the string contains javascript. for example:
$js = "some regular text which is not javascript##now vim has
detected that this part is javscript##back to regular text";
parse($js);
function parse($str)
{
return str_replace('##', '', $str);
}
The reason I would be happy to do this is because I will probably be incorporating a html/css/js variable minifier into my project which will be doing substitutions on strings anyway.
Of course if there is a vim-specific equivalent character for ## which will not show up in the source code and would not need to be filtered out then this would be preferable...
re-edit 2
As per conner's solution below, the desired effect can be achieved like so:
$js = "<script>some javascript</script>";
(with :let php_htmlInStrings=1 in vim). If somebody can show me the vim script required to get the javascript syntax highlighting to show up in the following string then I will award them the answer:
$js = /*<script>*/"some javascript"/*</script>*/;
I think the general problem with this is that vim needs a way to differentiate between the javascript and HTML highlighting. In HTML files, vim determines this based on the <script></script> tags within it to apply the javascript highlighting. If you put <script></script> tags in your string you'll see that this is the case. However, if you take those away then vim has no way of knowing if the content in your string is HTML or javascript. You could remedy this by editing adding something to signify that it's javascript that hopefully wouldn't effect the resultant code, but this is tricky. You can see where the HTML file is setting the <script></script> tag specification on line 167 of $VIMRUNTIME/syntax/html.vim. It looks like this:
syn region javaScript start=+<script[^>]*>+ keepend end=+</script>+me=s-1 contains=#htmlJavaScript,htmlCssStyleComment,htmlScriptTag,#htmlPreproc
Have you tried this php.vim syntax file?