自动关闭 html 标签和记事本 ++ 中的 jsp、php、asp 标签,并在脚本编写的行末尾添加分号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20373962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:07:47  来源:igfitidea点击:

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

phphtmlnotepad++

提问by Ravi MCA

I use notepad++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 ?>)
  1. 自动关闭 HTML 标签。(例如。</div>
  2. 以 .jsp、.asp、.php 文件的适当缩进开始后关闭标签。(例如<%%><?php?>
  3. 默认情况下在行尾放置一个分号(每当我在里面开始一个新行时<?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 .htmlor .htm

对于 (1),当我想在 php 文件中编写 HTML 标签时,这对我来说真的很令人沮丧。我升级到6.5.1,并尝试了TextFX,但它仅适用于具有扩展名.html.htm

Could someone please guide me in achieving these features?

有人可以指导我实现这些功能吗?

回答by Noha Kareem

Regarding auto-closing html tags, for me only having html as the language didn't do the trick.

关于自动关闭 html 标签,对我来说只有 html 作为语言并不能解决问题。

(This answer is incomplete, but is too large for a comment given the images.)

(这个答案不完整,但对于给定图像的评论来说太大了。)



Changing the auto-complete preferences, as below, worked:

更改自动完成首选项,如下所示,有效:

  • Settings> Preferences
  • 设置>首选项

settings_prefs

settings_prefs

  • Auto-Completiontab > Auto-Insertsection > html/xml close tag
  • 自动完成选项卡 >自动插入部分 > html/xml 关闭标记

auto-insert

自动插入

I use Notepad++ v6.5.2

我使用 Notepad++ v6.5.2

回答by Scott M. Stolz

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.

如果您正在编辑 PHP 文件并希望它自动完成 HTML 标记,除了在首选项中打开“自动插入 HTML/XML 标记”之外,您还必须在编辑该文件时将编程语言更改为 HTML。

In Notepad++, go to the Languagemenu, and find HTMLand click on it.

在 Notepad++ 中,转到语言菜单,找到HTML并单击它。

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

这会将文件的语言设置为 HTML,以便自动完成标记可以在 PHP 文件中使用。

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.

即使语言设置为 HTML,它仍然将 <?php ?> 标签中的任何内容突出显示为 PHP 代码,并且它不会影响括号的自动关闭(如果您启用了该功能)。

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

您必须打开自动插入 html/xml 关闭标签,如 Noha 的回答中所述。

  • Settings > Preferences
  • Auto-Completion tab > Auto-Insert section > html/xml close tag
  • 设置 > 首选项
  • 自动完成选项卡 ​​> 自动插入部分 > html/xml 关闭标记

回答by Boyan Alexiev

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.

对于 2. 您不能为自动完成(在自动插入部分)输入两个字符的自定义对。所以没有插件这是不可能的。如果我找到一个,我会更新我的答案。

  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).
  1. 但是,对于带有分号“;”的自动关闭代码,您可以使用此选项和“技巧”Notepad++ 不将其放在 php 标记内的每一行上(我认为这不是一个好的用例),而是将其放在仅在需要时。我测试了; 和 ; 作为开始和结束标签,这本质上为您提供了您需要的东西(尽管没有检查 php 标签),但它并不是那么好。但是,如果您使用“$”开头的标签和“;”结尾的标签,那么无论何时使用变量(这意味着您正在编写代码),您都可以获得自动关闭功能。

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.

请注意,使用 < 和 > 或任何其他类似的配对会破坏其他自动完成功能(包括自动关闭 html 标签)。这当然很糟糕,因为让 <> 自动关闭和 html 标签自动关闭会很好。