Auto close of html tags and jsp, php, asp tags in notepad++ and a semicolon at the end of the line written of scriptlets

Viewed 71372

I use and I like it

I specifically want it to do this :

  1. Close automatically HTML tags. (eg. </div>)
  2. Close tags after starting with proper indention for .jsp, .asp, .php files. (eg.<% %>, <?php ?>)
  3. Put a semicolon at the line end by default (whenever I start a new line inside <?php ?>)

For (1), it is really frustrating for me, when I want to write HTML tags in php files. I upgraded to 6.5.1, and tried the TextFX, but it works only with files which have the extension .html or .htm

Could someone please guide me in achieving these features?

3 Answers

If you are editing a PHP file and want it to auto-complete the HTML tags, in addition to turning on "Auto-insert HTML/XML tags" in Preferences, you have to change the programming language to HTML while editing that file.

In Notepad++, go to the Language menu, and find HTML and click on it.

This will set the file's language to HTML so that auto-complete tags will work in a PHP file.

Even with the language set to HTML, it still highlights anything in <?php ?> tags as PHP code, and it does not affect auto-closing of brackets, if you have that enabled.

You must have Auto-Insert html/xml close tags on, as mentioned in Noha's answer.

  • Settings > Preferences
  • Auto-Completion tab > Auto-Insert section > html/xml close tag

For 2. you can't enter custom pairs for auto-complete (in the Auto-Insert section) with two characters. So this is not possible without a plugin. If I find one, I will update my answer.

  1. However, for auto closing code with semicolon ";", you can use this option and "trick" Notepad++ to not put it on every line inside a php tag (which I don't believe is a good use case), but put it only when needed. I tested with ; and ; as opening and closing tags, which essentialy gives you what you need (without the php tags check though) and it's not so nice. But if you use an opening tag of "$" and a closing one ";", then you can get an auto-close functionality whenever you use a variable (which will mean you are writing code).

Please note that using < and > or any other similar pairs will break other auto-complete functionality (including the auto-close html tags). This is certainly bad, because it would be nice to have both <> auto close and html tags auto-close.

Related