[prog] replacement strings
Sam Watkins
sam at nipl.net
Tue May 25 11:03:19 UTC 2010
> I've been spending hours trying to find something that does the same
> thing as TextPad's join command. (I really want to get rid of my need
> for wine.)
Vim has a join command, you can run it with shift-J: select some lines in
"visual mode" (v or V), then press J.
I assume emacs has some join-lines command or similar too.
> It joins highlighted text into single lines, keeping paragraphs
> distinct.
aha I see what you mean, that's different.
This perl one-liner can do it. It chomps off all the newlines, but if it sees
a blank line, it outputs a double newline.
perl -pe 'chomp; print "\n\n" if $_ eq "";'
If you want it to deal with poetry, I guess you could indent your poetry and do
like:
perl -pe 'chomp unless /^ /; print "\n\n" if $_ eq "";'
or otherwise think of how you want that to work.
> The closest I've been able to find is the fmt command (part of the Gnu
> coreutils, and should be in most linuxes). Unfortunately that has an upper
> limit of 2,500 characters in a paragraph
I guess fmt wasn't written with that in mind, but it is consistent with its
function. It's a bit bogus to have a limit like that, I thought the GNU tools
got rid of such arbitrary limits. It should have an "unwrap" option where it
never breaks a paragraph, then it would do what you want. Might be a case for
patching fmt, it is open-source after all.
You could try the perl modules Text::Format or Text::Wrap too.
In vim and other decent editors, you can apply any script to a chunk of text.
For example, in vim, highlight some text with V (visual line mode) then type
:!fmt -w 20
You can undo it with u.
Sam
More information about the Programming
mailing list