Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editor showdown: Maintain newlines at the ends of sentences

When editing non-WYSIWYG (LaTeX, HTML, etc) prose you probably want to have newlines at the ends of your sentences. This has several advantages:

  1. Easier to rearrange sentences.
  2. Easier to comment out sentences.
  3. Easier to spot run-on / overly long sentences.
  4. 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.

like image 930
dreeves Avatar asked Feb 12 '09 21:02

dreeves


5 Answers

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),

like image 189
yungchin Avatar answered Nov 18 '22 13:11

yungchin


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:

set comments=b:%
set textwidth=80
set formatoption+=c
set formatoption-=t

This is the method I use, so that my comments are tidy, but my code doesn't get mangled unless I do it myself.

like image 37
too much php Avatar answered Nov 18 '22 11:11

too much php


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.

like image 28
Gnudiff Avatar answered Nov 18 '22 13:11

Gnudiff


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.

like image 1
Jason Blevins Avatar answered Nov 18 '22 11:11

Jason Blevins


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.

like image 1
Andrew Wagner Avatar answered Nov 18 '22 11:11

Andrew Wagner