Newbie: Call Register for every line in File

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Newbie: Call Register for every line in File

Thomas Reiss
Hi,

as Newbie i need a little Help.

I have a File

1
2
3
4
5

the i will reformat to

1|2|3|4|5

so i have do (one first line)

qa A|<ESC>J q

How can I repeat these commands for every Line in the File?

My only Idea is to go on the Last Line, look what was the Linenumber, go
back to the First line and call

5@a

So, can i substitute "5" to a "magic Key"?

Thank You
Thomas

Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Call Register for every line in File

Tim Chase-2
> I have a File
>
> 1
> 2
> 3
> 4
> 5
>
> the i will reformat to
>
> 1|2|3|4|5
>
> so i have do (one first line)
>
> qa A|<ESC>J q
>
> How can I repeat these commands for every Line in the File?

It's easiest to understand in two passes:
        :1,$-1s/$/|
        :1,$j

should do the trick.  Although you may want to use "j!" instead
of "j" to get the results you describe (sans-whitespace)

-tim




Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Call Register for every line in File

Will Maier
In reply to this post by Thomas Reiss
On Fri, Jul 22, 2005 at 06:27:37PM +0200, Thomas Reiss wrote:
> My only Idea is to go on the Last Line, look what was the Linenumber, go
> back to the First line and call

That might work, but here's another approach:
    :%s/\n/|/
This regular expression will turn all new-lines (\n) into pipes (|); input like
    1
    2
    3
    4
    5
would become
    1|2|3|4|5

While this seems sufficient in your case, you might want to spruce the RE up a
bit; if the scenario you presented to the list is simplified, this RE probably
misses important subtleties in the document you're editing.

--

Will Maier

Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Call Register for every line in File

A.J.Mechelynck
In reply to this post by Thomas Reiss
----- Original Message -----
From: "Thomas Reiss" <[hidden email]>
To: <[hidden email]>
Sent: Friday, July 22, 2005 6:27 PM
Subject: Newbie: Call Register for every line in File


> Hi,
>
> as Newbie i need a little Help.
>
> I have a File
>
> 1
> 2
> 3
> 4
> 5
>
> the i will reformat to
>
> 1|2|3|4|5
>
> so i have do (one first line)
>
> qa A|<ESC>J q
>
> How can I repeat these commands for every Line in the File?
>
> My only Idea is to go on the Last Line, look what was the Linenumber, go
> back to the First line and call
>
> 5@a
>
> So, can i substitute "5" to a "magic Key"?
>
> Thank You
> Thomas

To repeat

    A|<Esc>J

for all lines in a file, use

    :1,$normal A|^[J

where ^[ is obtained by hitting Ctrl-V (or Ctrl-Q if you use Ctrl-V for
pasting) followed by Esc. You may or may not have to insert ^V (obtained by
hitting Ctrl-V twice) just before the ^[ (I think not but I'm not sure).

Or use :1,$-1 as the range to do it on all lines except the last.

If you already have A|^[J in register a, you may enter it on the
command-line by hitting Ctrl-R a (unless the ^[ in the middle "escapes" away
from the command-line).

HTH,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Call Register for every line in File

Thomas Reiss
Hello Tony Mechelynck,

thanks for help

>
> To repeat
>
>    A|<Esc>J
>
> for all lines in a file, use
>
>    :1,$normal A|^[J

the result ist:

1| 2
3| 4
5| |||

But i see some another topic's for me.

Thomas

Reply | Threaded
Open this post in threaded view
|

Thank's all for: Call Register for every line in File

Thomas Reiss
In reply to this post by Thomas Reiss
Thanks for all Hint's and Tricks.

Look's easier that i think....

Thomas

PS: sorry for typos