Not browser, not cross-platform, but might be useful for someone anyway:

TextMate for Mac OS X has the command Edit » Unwrap Paragraph/Selection (Ctrl-Opt-Q) for exactly this purpose.


Emacs has M-q for this purpose, you might have to assign a greater width than default.


Use the following Python script (written on OS X, but otherwise cross-platform):

#!/usr/bin/env python
import sys

current = "\n"
for line in sys.stdin:
    if line != "\n":
        sys.stdout.write(current[:-1])
    else:
        print "\n"
    current = line
print current[:-1]

Invoke like this:

cat test.txt | ./rewrap.py

On Mac OS X, create a Service using Automator in any application that receives text as input and replaces selected text. Add a Run Shell Script action that passes input to stdin and call the Python script above. Assign a global keyboard shortcut for any application in System Preferences » Keyboard.

alt text


Check out Clipboard Fusion by Binary Fortress Software. I have it set so when ever I copy text from certain applications (Adobe Reader), copied text is automatically stripped of line breaks. Very useful.


(G)Vim can do this. E.g., put this in your .vimrc:

vnoremap <F5> :s/\s*\n\s*\n\s*/<<mybreak>>/g<CR>gvJgv:s/<<mybreak>>/\r\r/g<CR>

This assigns the key F5 (you can use whatever you want instead; with vim you can customize all the keymappings however you want) to do all the following: while in "visual mode" (i.e., when a block of text is selected), replace all linebreaks in the selected text followed by a line with nothing but whitespace followed by another linebreak with the placeholder <<mybreak>>, rehighlight the same portion and join all the lines, reducing all whitespace between lines to a single space,, rehighlight the same portion and replace the placeholder <<mybreak>> with two newlines to restore the paragraph breaks.

Of course, you don't need to remember anything but F5.

Actually, there's probably a simpler way to do this in vim. My vim skills are nothing compared to some; this is just how it occurred to me to do it.

Can you use it in a browser: perhaps not directly, but with Firefox plugins such as vimperator or pentadactyl allow you to edit all webfields in vim (or any other text editor of your chosing), so then you'd be able to use it there too.


using AutoHotkey (open-source):

This code will allow you to copy to the clipboard (using CTRL+ALT+C *) and unwrap it (ready to be past). Like a normal copy past, and it will keep empty lines between paragraphs.

!^+c::                 ;copy + unwrap but keep the empty lines
clipboard =
Send, {CTRLDOWN}c{CTRLUP}{ESC}
ClipWait
NewStr := RegExReplace(Clipboard, "([^\r\n])\R([^\r\n])", "$1$2")
clipboard = %NewStr%
ClipWait
return
  • you can change your shortcut by any key just by changing the first line.