Michael Dacre wrote:
> hey tim
> thanks for the advice :)

Just for future reference, it's best to use your mailer's Reply
To All (or "Reply to List") functionality, so that the ML gets
copied.  My filters flagged your message as junk and moved it
into my overflowing junk-mail folder because it came to my vim-ML
address but wasn't sent to the list (and you weren't already in a
whitelist of Vim-list folks with whom I occasionally correspond
off-list).  Additionally, my vim domain-knowledge only extends so
far.  If I don't have the answer, there's a good chance many of
the other smart folks on the list can help you out.  Or I may get
something totally wrong.  But if you don't CC the ML, you lose
that resource.

> sorry about my terrible description - wasnt sure how to phrase it.  First of
> all i meant javascript not java - what i am trying to do is create a form in
> which people can add extra tables by clicking a link.  The table is in html
> but the link is obviously js (i.e. I am using the command newdiv.innerHTML =
> "...") but to do that it requires that there are no returns.  I can remove
> them manually but it's a pain as I need to do it for a few different forms.

Now I'm confused...it sounds like you want to do this in
JavaScript, not vim-script.  And it also sounds like you want to
do this on an automated basis, so that every time a row is added,
it cleans up whatever was submitted?

If you have a number of files that need to be cleaned up in one
pass, you can use the argdo/windo/bufdo/tabdo functions to
perform an Ex command across a number of files.  Ex commands can
take ranges that give you more surgical-strike capabilities if
you need them, so you can only change ranges of lines if needed.
 However, if you have a bunch of files, you can do something like

        sh$ cd /path/to/files
        sh$ vim *.txt
        :set hidden
        :argdo %j
(review your files here, and if they're okay, continue)
        :wall

That "%j" can be any Ex command, so you can do things like

        :argdo 1,10j

to join the first 10 lines of the file or

        :argdo g/STARTTEXT/+,/ENDTEXT/-j

to every line after "STARTTEXT" through every line before
"ENDTEXT".  If the text to join is embedded in your HTML/JS
files, this might help isolate the contents so you're only
joining germane lines.

-tim

> On 5/26/07, Tim Chase <[EMAIL PROTECTED]> wrote:
>>> I have been trying to figure out how I can replace all the new line
>>> characters in a text file with spaces - need to do this to make html
>>> compatible with java and am too lazy to do it manually every time.
>>>
>>> Am sure there is a simple way to do it but I have looked and cant figure
>> it
>>> out :(
>>
>> Well, if you plan to do it regularly, you can use "tr" to do
>> exactly what you describe:
>>
>>
>> tr '\012' \040' <in.txt >out.txt
>>
>> Or, if you want to do it in vim, you can do:
>>
>>         :%j
>>
>> which will join all the lines in your file, normalizing
>> whitespace.  If you don't want Vim to be smart about it, you can
>> tell it to simply remove the newlines:
>>
>>         :%j!
>>
>> Alternatively, you can use
>>
>>         :%s/\n/ /
>>
>> which will do the same thing as the "tr" command, only it will
>> appropriately leave a \n at the end of the file.
>>
>> As a side note, I'm not sure what it meens to "make html
>> compatible with java", as they're fairly disjoint languages.  One
>> is for markup; the other is for execution. :-/
>>
>> -tim


Reply via email to