I'm editing a saved .php file in Sublime Text 3 (build 3126 for mac), and when I try to comment something out using cmd+/, Sublime inserts the standard HTML comment
<!-- -->
Sublime does not comment out when I try to use DocBlocks, /* */, # or //.
I've checked and Sublime is currently set to PHP syntax, as it should be. The Build System is set to Automatic. Has anyone ever experienced this and do you know of a fix? I couldn't find this problem anywhere on StackExchange and the only thing I found on Google was:
https://forum.sublimetext.com/t/cant-set-syntax-to-php/7478/8
Since their symptoms don't exactly match mine, I thought I'd ask here before I go as far as clearing caches that I don't know much about.
Maybe this answer is too simple, but it might be your case:
In SublimeText3 when opening comments using Ctrl+/ or Ctrl+Shift+/:
When editing brand-new empty saved .php file, sublime use HTML comments <\!-- -->
But when you open a PHP tag, AND your cursor is inside it, Sublime uses right PHP comments /* */ or //
So it's context sensitive. It uses PHP comments only inside PHP code fragments.
Remember that PHP opening tag is required even in pure PHP-code files.
Related
I did following in order to include php code into Joomla:
writing a php application with jumi as:
<?php echo '<p>Hallo Welt</p>'; ?>
include following code in the target article, where the previous code should be included:
{jumi [*1]}
this worked so far.
But, when i try to edit the article again using the wyiwyg editor, the editor take the resolved formatting, means Hallo Welt and the original code get replaced {jumi [*1]}
this is get very problematic when the code is dynamic!
does somebody has a solution for this issue or am I missing something?
No It's a common problem, no worries.
There are several hack you can do to avoid this.
Save the text in one file and every time edit the file and after copy and paste in Joomla.
When you edit the file, just edit from the source.
Use an alternative editor which is already in source mode like RokPad
Check Plugin Manager > Editor - TinyMCE > Entity Encoding = raw
Using sourcerer plugging for including php script into an article, does not cause this overriding of source code by the displayed result, that's why I was forced to stop using jumi in favor of sourcerer.
Switching to raw mode is unfortunately not an option, since this would increase the effort of other authors who are supervising the platform and typing articles, especially when those are not so familiar with plain HTML.
In net beans you can quickly create templates for things like classes and assigned chunks of text to short cuts etc.
How can I do this in Sublime Text. I have looked around the net and can't find a simple example.
1) First of all make sure you have the correct syntax defined for the file you are working on (usually in the bottom right corner in sublime text).
2) Then be sure to have the cursor inside the <?php ?> tags.
3) Using your example of creating a class, simply start typing the keyword class and hit the tab or enter key to execute the existing, built-in snippet of sublime text.
4) You should see a basic code structure in your code now. Using the tab key again, you can jump through the snippet and adjust the parameters to your needs.
If you need more customized snippets, there is also the possibility of creating your own.
Go to Tools -> New Snippet... in the sublime menu. The syntax is difficult to describe, that's why I would recommend reading on about sublime snippets here:
http://docs.sublimetext.info/en/latest/reference/snippets.html
There are also many packages available for sublime that add extra snippets to your editor. Have a look here (be aware that you need Package Control installed):
https://sublime.wbond.net/browse
Cheers! Hope this helps!
My first place to look at this was a fix with Notepad++.
This quite quickly brought me to "TextFX HTML Tidy".
Read the description and it seemed to be the problem for all my problems.
However, the install is quite hard, apparently TextFX used to be standard practice for Notepad++, for some reason that is no longer the case. I eventually fixed this by downloading an older install for Notepad++ and copied the plugin folder to my own Notepad++ file.
This gave me acces to the correct plugin, but this plugin is written purely for HTML, C++, or XML.
Since I use php in my files, this gives some complications. Normal tags are ignored as they should be, but when I use php inside an html string, in a link for instance, the php tags get converted to html.
For instance:
The start of my sentence Here my anchor tekst.
After tidy HTML becomes
The start of my sentence Here my anchor tekst.
Rendering this solution unusable.
There must be a lot of people looking for this functionality, and since this one is no longer standard practice for Notepad++, I figured there must be a better method to auto format your HTML code. But for some reason I can't find it.
So my question is: Is there a way to autoformat my code, clearing empty lines and indenting tags in the correct opening and closing order?
Preferably with Notepad++ but any other program will do.
Kind regards
For anyone looking for the same things. Switching to Netbeans did the trick for me, options with Notepad++ are still appreciated.
In Netbeans, using Shift+alt+F did the trick for me.
I think I have accidentally overridden one of the default settings in the NetBeans editor (7.2 on Windows 7) and a beautiful feature is gone.
Bracket completion feature is now effected.
I am new to NetBeans. When I used to type
echo "
NetBeans used to place the matching " and put the cursor right after the first quote
echo "|"` // here the `|` denotes the cursor
So when I see the cursor there, I just type... And when I am done typing, I used to be able simply to hit enter (while the cursor is still inside the closing quote) and NetBeans used to automatically put the semi-column at the end of the line (after the closing quote) and advance me to the next line - very nicely. But now, the enter totally creates a new line, pushing the closing quote also to the next line. And obviously, no more semi-column.
So I end up getting this now
echo "test
"
The enter used to give me this instead;
echo "test";
I wonder what went wrong and where. Now I have to hit right arrow to get to the right side of the closing quote and place a semi-column manually and then hit enter.
How do you bring back default settings? What do you do in situations like this?
Running Windows 7 and NetBeans 7.2.1
General answer to your question
The settings are stored in XML files in your user directory:
Example
${userdir}/config/Editors/text/{PROGRAMMING_LANGUAGE_HERE}/Preferences/org-netbeans-modules-editor-settings-CustomPreferences.xml.
If you delete this file the language settings (including formatting) will be set to default.
I'm not totally sure that feature is in the language setting, but just check the config directory and delete files until that feature is back!
You can also delete specific parts of the XML file to reset only some settings.
Alternative to your specific problem (Alternative 1)
After the discussion in the comments and some search, I found this link as an alternative to your specific request. I'll still leave the original answer there since it answers the question in the title (and to help with future people who use the search function).
Netbeans Tip: Adding a semicolon to the end of a line for PHP
When writing Java in Netbeans there is a handy shortcut that places a semi-colon (;) at the end of the line, simply by pressing ctrl+;. That doesn’t sound like a big deal, but it seems I often write a piece of code yet somehow not have a semi-colon at the end. I think it’s to do with the code complete (eg. The IDE never quite lets me get to the end of the line before I finish writing the code I want to write – it’s a good thing really). However, this feature isn’t available when writing PHP.
Proof of how handy I actually find this shortcut is that I’m now forever trying to do it in Netbeans when writing PHP, only to be left disappointed.
How to do it in Netbeans for PHP
However, there’s a quick way to create this functionality in Netbeans (and any editor that provides macros support):
In Netbeans, click somewhere in the text editor.
Select Edit > Start Macro
Now whilst in the editor, press the ‘end’ key followed by the ‘;’ key. You should now have a semicolon at the end of your line.
Select Edit > Stop Macro
Give your macro a name (eg. “Append ;”)
Click ‘Set Shortcut’
Press “ctrl+;” and click OK
You’re done!
Alternative to your specific problem (Alternative 2)
Also, in Options -> Editor -> Code Templates, you have a bunch of templates, including a eco shortcut which does EXACTLY what you want (double quotes, ;, etc..)! For some reason, those templates won't work for me with the default setting "Expand Template On TAB", but if I change it to CTRL+SPACE, it works perfectly!
I recently got hired as a web developer, and the project that I am overseeing has a formatting issue on one of the pages because one of the divs is out of whack. It is a fairly complex page with quite a bit of php, and from what I can gather, I am missing a </div> tag somewhere, and accordingly everything is messed up.
I am currently using notepad++, which is decent at lining up divs, meaning that if you click on the opening div tag, it will highlight purple and also highlight the closing one. But it seems as though if you have div tags that span several lines (hundreds) it won't work.
Has anyone else run into a similar situation? Is there a better editor I could be using that would do a better job of helping me with my div issue? Or do I have to go through and line up the divs 1 by 1? (there are like over 100). Please let me know!! Thanks
An alternate route I would like to suggest is running your page through a validator, such as the W3C service at http://validator.w3.org
HTML Validator is an addon for Firefox that can automatically run your pages through a local validator and notify you of any issues with an icon in the satus bar.
You want an editor that detects and highlights syntax errors in markup (as well as validity). There are many. I use Komodo Edit from ActiveState (www.activestate.com)
A cross platform solution is Eclipse (PDT). It comes with a nice and handy html editor. For quick file changes and hotfixes I use TextMate – but this is OS X only :(
Sometimes, when I have crazy X/HTML that I am trying to clean up/debug I put it into an XML editor and let it do some of the matching/formatting for me. My personal choice is Altova's XMLSpy. It is not free (hell, it's not even cheap), but I really like the power it has. You can download a free demo from their website and see if it helps you out.
Like what others have said, use a free editor like Eclipse. Open your HTML in Eclipse, then press CTRL+SHIFT+F and it will format and indent the code, just like what Notepad++ does.
Is this page already online in public area?
If yes, did you try to validate the HTML/XHTML with W3C validator http://validator.w3.org/, it might tell you the exact line where the closed DIV tag is missing.
UPDATE: you can also copy and paste code of the page deirectly into the validator and validate it: you go with your browser at the page, then you select "View Source" from the browser manu, than you copy & paste code into W3C validator.
You could try using a more "Powerful" editor such as Eclipse or Netbeans. I use Netbeans for most of my HTML / PHP development, and it does a good job of highlighting matching tags.
Vim + matchit plugin
I use http://users.rcn.com/creitzel/tidy.html#tidyui for fixing html.