记事本++:禁用空行后自动缩进
我发现 Notepad++ 的自动缩进风格有点奇怪:当我在缩进的行上打字时,我确实希望它在我按 Enter 后缩进下一行(这是正确的)。 但是,当我在空行上(没有缩进,没有字符)并按 Enter 时,它会缩进下一行,并使用与最后一个非空行相同的缩进。 我觉得这非常烦人; 您遇到过这个问题吗?您知道如何解决吗?
(注意:我正在编辑 HTML/PHP 文件。)
I find the autoindent style of Notepad++ a little weird: when I am typing on an indented line, I do want it to indent the next line after I press Enter (this it does properly). However, when I am on an empty line (no indentation, no characters) and I press Enter, it indents the next line, using the same indentation as the last non-empty line. I find this extremely annoying; have you ever encountered this problem and do you know how to fix it?
(Note: I'm editing HTML/PHP files.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我在 Notepad++ 中所做的是:
我会告诉您如何录制使用另一个宏的宏,但几年前我就做到了,现在我只是复制文件。 我希望它可以正常工作,或者可能我是通过手动编辑快捷方式文件来完成的。 它看起来像这样(在 Shortcuts.xml 中):
两个警告:
修剪宏有错误。 仅当使用时光标位于行尾时它才有效。 我偶尔会考虑尝试修复它或自己做,但永远不会被打扰,因为我在保存之前通过自己移动光标反射性地解决它。 可以将相同的解决方法内置到“修剪并保存”宏中。
如果您从“他们的”文件中删除尾随空格,有些人会感到不安 - 要么是因为他们喜欢它,要么是因为他们有时使用 diff 而不忽略空格(例如在更改报告中)并且不希望看到您这样做已经改变了一半的文件,而实际上它只是一句台词。 因此,对于这些文件,只需保留尾随空格不变,并使用 alt-fs (或您移动保存到的“其他内容”)而不是 ctrl-s 保存。 您可能需要将 Notepad++ 设置为在保存时不清除撤消缓冲区:否则这里的错误将是一场灾难。 但我还是这样设置的。
What I do in Notepad++ is:
I'd tell you how to record a macro that uses another macro, but it's years ago I did it and now I just copy the file around. I expect it Just Works, or possibly I did it by manually editing the shortcuts file. It looks like this (in shortcuts.xml):
Two warnings:
The trim macro is buggy. It only works if the cursor is at the end of a line when it's used. I occasionally think about trying to fix it or do my own, but can never be bothered because I reflexively work around it by moving the cursor myself before saving. The same workaround could just be built into your "trim and save" macro.
Some people get upset if you strip trailing whitespace out of "their" files - either because they like it, or because they sometimes use diff without ignoring whitespace (for instance in change reports) and don't want to see that you've changed half the file when really it was a one-liner. So for those files, just leave the trailing whitespace as it is and save with alt-f-s (or the 'something else' you moved save to) instead of ctrl-s. You probably need to set Notepad++ not to clear the undo buffer on save: otherwise a mistake here would be a bit of a disaster. But I set that anyway.
老实说,这对我来说似乎是意料之中的行为。 我自己经常使用空行来分解代码以使其更具可读性,让程序让我必须再次退出会非常烦人。
我可以将其理解为对 Python 之类的挫败感,但对 PHP 则不然……不过,在大括号等之前,这可能很烦人。
尝试 Komodo Edit 但是,它是免费的,而且我发现它一般来说,对我来说自动缩进是最好的。 它似乎已经了解了我的编码风格(或者其中包含所有编码风格的选项,并且它会选择您正在使用的内容)并自动正确缩进所有内容。
编辑:正如您在回复中指出的,问题在于“尾随空格” - 我不太了解 Notepad++,但大多数为编码而设计的现代编辑器都有一个“保存时删除尾随空格”选项(我知道 Komodo做!)
To be honest, this to me seems expected behaviour. Blank lines are used a lot by myself to break up the code to make it more readable, having the program make me have to tab out again would be VERY annoying.
I can understand this as a frustration with something like Python, but not with PHP... Though, before braces etc etc this might be annoying.
Try out Komodo Edit however, it's free, and I've found that it generally has been the best for auto-indenting for me. It seems to have learnt my coding style (or have the options in it for all coding styles and it picks up what you're using) and automatically indents everything correctly.
Edit: As you've noted in your reply, the issue is with "trailing whitespace" - I don't know Notepad++ too well, but most modern editors designed for coding have a "strip trailing whitespace on save" option (I know Komodo does!)
您可以参考此设置并记下“选项卡大小”。
You can refer this setting and note the "tab size" .
修剪尾随空格并保存很烦人。 您会注意到您无意中向文档中插入了一些字符。
相反,录制一个宏并将其绑定到您的 ctrl + s。
操作方法如下:
Trim Trailing Space and Save is annoying. You'll notice that you are inserting few characters to documents unintentionally.
Instead record a macro and bind it to your ctrl + s.
Here is how to do it:
不幸的是,Notepad++ 不会自动修剪第二个空新行。 但是,作为一种解决方法,我同意 user108570:一个宏就完美了。
我喜欢在概念上区分“软”与“硬”换行符,类似于两种类型的制表符。 前者的输出取决于当前的样式和缩进设置。 然而,后者的输出应该始终是一个简单的、纯粹的、普通的换行符。
当然,最常用的换行风格应该映射到更简单的组合键。 对于大多数编辑,您可能希望将“软换行”映射到“Enter”键,并更改“Ctrl+Enter”以触发“硬换行”。
在“菜单 -> 设置 -> 快捷方式映射器 -> 主菜单”中,您将看到默认情况下“Ctrl+Enter”映射到“单词完成”。 需要首先将其映射为“无”来禁用它。
然后简单录制一个宏:
最后一步将弹出一个对话框,您可以在其中命名宏(例如“硬换行”)并设置其映射(即“Ctrl+Enter”)。
在第 3 步,我们可以添加任何内容(可打印)。 它的唯一目的是添加一些要删除的内容(如果之前没有任何内容),以便光标后面的任何文本都将保持不变。
It is unfortunate that Notepad++ doesn't trim the second empty new line automatically. But, as a work-around, I agree with user108570: a macro would be perfect.
I like to make a conceptual distinction between "soft" versus "hard" linefeeds, analogously to the two types of tabs. The output of the former depends on the current style and indentation settings. The output of the latter, however, should always be a simple, unadulterated, plain vanilla new-line.
The most frequently used flavour of linefeed should, of course, be mapped to the simpler key-combination. For most of your editing you would probably want to leave "soft linefeed" mapped to the "Enter" key and change "Ctrl+Enter" to trigger a "hard linefeed".
In "Menu -> Settings -> Shortcut Mapper -> Main Menu" you will see that by default "Ctrl+Enter" is mapped to "Word Completion". This needs to be disabled first by mapping it to "None".
Then simply record a macro:
The last step will pop a dialog where you would name the macro (e.g. "Hard Linefeed") and set its mapping (i.e. "Ctrl+Enter").
At step 3 we could have added anything (printable). Its sole purpose is to add something to delete if there was nothing before, so that any text following the cursor will remain untouched.
1)如果没有NppAutoIndent插件,请先安装它。
2)可以通过执行以下操作来关闭此行为:
3) 如果此选项被禁用,您可能需要首先检查此选项:
1) First install NppAutoIndent plugin if you don't have it.
2) This behavior can be turned off by doing:
3) If this option is disabled, you may need to first check this option:
我可以确认 Notepad++ 版本 5.0.3 会出现此问题。 我找到的唯一相关设置是在“设置”>“设置”下。 首选项> 其他> 自动缩进,但这只是打开或关闭所有自动缩进。
我过去使用过 Editra (http://editra.org),并且对它很满意,它似乎可以处理缩进你描述的方式。
I can confirm that this issue happens with Notepad++ version 5.0.3. The only related setting I have found is under Settings > Preferences > MISC > Auto-Indent, but that just turns all auto-indenting on or off.
I have used Editra (http://editra.org) in the past and was happy with it and it appears to handle indenting the way you are describing.
我找到了另一种方法:
使用宏“修剪尾随并保存”快捷方式“Alt + Shift + S”
我你一直需要这个,只需将保存快捷方式与宏“修剪尾随并保存”快捷方式交换即可-切。
我只在编程时倾向于使用 notepad++,所以这对我来说很有效。
I found another way:
Use the macro "Trim Trailing and save" short-cut "Alt + Shift + S"
I you need this all the time, just swap the save short-cut with the macro "Trim Trailing and save" short-cut.
I only tend to use notepad++ when I'm programming so this works well for me.