编辑摊牌:在句子末尾保留换行符
编辑非所见即所得(LaTeX、HTML 等)散文时,您可能希望在句子末尾添加换行符。 这有几个优点:
- 更容易重新排列句子。
- 更容易注释句子。
- 更容易发现连续/过长的句子。
- 更容易对句子进行评论。
例如:
% The following isn't strictly true; maybe excise or comment out for now:
After all, people who use Word or other WYSIWYG editors are aiding and
abetting terrorists.
最重要的优点可能是它使版本控制下的协作编辑变得更加容易。 否则,您最终会遇到冲突,它只会告诉您“这个大段落的以下两个版本存在冲突”。
但是在句子末尾维护换行符说起来容易做起来难...
As you edit the prose
it will get all chopped up, like this.
Normally you'd do a "reformat paragraph"
to clean it up, but then
you lose the newlines at the ends of your sentences!
以下问题询问如何在 emacs 中解决此问题:
我想知道人们如何在其他编辑器中处理这个问题,包括 vim、TeXShop、 TextMate 以及您认为有用的任何其他内容都可以在这里收集。 也欢迎有关软包装和硬包装的建议。
When editing non-WYSIWYG (LaTeX, HTML, etc) prose you probably want to have newlines at the ends of your sentences.
This has several advantages:
- Easier to rearrange sentences.
- Easier to comment out sentences.
- Easier to spot run-on / overly long sentences.
- Easier to comment on sentences.
For example:
% The following isn't strictly true; maybe excise or comment out for now:
After all, people who use Word or other WYSIWYG editors are aiding and
abetting terrorists.
And probably the most important advantage of all is that it makes collaborative editing under version control much easier.
Otherwise you end up with conflicts where it just informs you "the following two versions of this huge paragraph are in conflict".
But maintaining newlines at the ends of sentences is easier said than done...
As you edit the prose
it will get all chopped up, like this.
Normally you'd do a "reformat paragraph"
to clean it up, but then
you lose the newlines at the ends of your sentences!
The following question asks about how to solve this problem in emacs:
How do I get Emacs to fill sentences, but not paragraphs?
I'd like to know how people deal with this in other editors, including vim, TeXShop, TextMate, and any others you think would be useful to collect here.
Advice on soft vs hard wrapping is also welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我认为最简单的解决方案是仅在句号后添加换行符。 这样您的编辑就不会造成线条碎片。
请注意,对于散文,您可以很好地依赖编辑器的换行功能来换行长句子 - 除非您坚持像使用代码一样缩进(我在乳胶中不会缩进那么多),
I'd think the simplest solution to this is to only add newlines after full stops. Your edits would then never fragment lines.
Note that for prose you can very well rely on your editor's line-wrapping features to wrap long sentences - unless you insist on indenting it like you would with code (I don't indent that much in latex),
Vim:
你可以关闭文本换行(
set formatoption-=t
),除非你按 Enter 键,否则它不会添加换行符。 更好的是,如果您知道如何设置'comments'
选项以便它识别您的评论,您可以仅为您的评论设置自动换行宽度,而不为其他任何内容设置自动换行宽度:这是我使用的方法,这样我的注释就很整洁,但是除非我自己做,否则我的代码不会被破坏。
Vim:
You can turn off text-wrapping (
set formatoption-=t
) and it will not add linebreaks unless you hit enter. Better still, if you can figure out how to set up the'comments'
option so that it recognizes your comments, you can set an auto-wrap width only for your comments and not for anything else:This is the method I use, so that my comments are tidy, but my code doesn't get mangled unless I do it myself.
普通的文本编辑器不应尝试更改您编写的文件,除非您明确要求它这样做。 它可能会更改文件在屏幕上的外观以提高可读性,但仅此而已。
因此,根据我的经验,大多数优秀的编辑器都会进行软包装,并在插入换行符的地方保留换行符。
就这样。 我必须承认,我看不出有什么大惊小怪的,除非您使用一些非常奇怪的文本编辑器,它们坚持进行硬包装并需要解决方法。
如果您想保持格式对 diff 有用,只需在每个句子后进行换行,并接受 diff 将在句子级别工作。
A normal text editor should not attempt to change the file you write, unless you explicitly ask it to. It may change file's appearance on screen for readability, but that's it.
Therefore most decent editors in my experience do soft wrapping and keep your line breaks wherever you inserted them.
That's all. I must confess I can't see what the fuss is about, unless you are using some pretty weird text editors that insist on doing hard wraps and need workarounds.
If you want to keep formatting useful for diff, just do the line breaks after each sentence, and accept that diff will work on sentence level.
在vim中,你可以用
gw)
填充到当前句子的末尾。它不会为您重新格式化整个段落或区域,但如果您
小心地在每个句子后插入换行符,然后重新格式化
当你写的时候使用
gw)
,它工作得很好。In vim, you can fill to the end of the current sentence with
gw)
.It won't reformat an entire paragraph or region for you, but if you
are careful to insert newlines after each sentence, and you reformat
with
gw)
as you write, it works pretty well.无论您做什么,如果您处于协作环境中,请不要使用自动硬包装整个文档的编辑器。 朋友不让朋友使用WinEdt。
Whatever you do, please don't use an editor that automatically hard wraps the entire document if you're in a collaborative environment. Friends don't let friends use WinEdt.
FWIW 在 Windows 平台上,Zeus 编辑器具有可配置的右边距 和内置的换行 函数。
例如,将右边距设置为 60 个字符,标记示例文本,然后使用宏、换行段落菜单,Zeus 将重新格式化文本,如下所示:
换行是硬,因为上面的所有行都有行尾字符插入。
FWIW on the Windows platform, the Zeus editor has a configurable right margin and a built in line wrap function.
So for example, with the right margin set to 60 characters, marking the text of your example and then using the Macros, Linewrap Paragraph menu, Zeus will reformat the text as follows:
The wrapping is hard in that all the lines above have a end of line character inserted.
你不希望在句子末尾出现换行符。
当然,做你列出的四件事更容易,但是与世界其他地方的做法不同,这是不值得的(即使世界上的理由像 CR LF = 换行符背后的推理一样愚蠢)。
而你最大的优势并不真实:
您可以使用 Meld 或类似的 diff 工具并让它完成工作。
you do not want newlines at the end of sentences.
sure it's easier to do the 4 things you list, but that is not worth doing it different from how the rest of the world does it (even if the world's reasons are as stupid as the reasoning behind CR LF = newline).
and your biggest advantage is not true:
you can use Meld or some similar diff tool and let it do the work.