inserting 1 - 100 (numbers) on consecutive lines

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

inserting 1 - 100 (numbers) on consecutive lines

luke-44
Hi.

Is there a way to insert into vi with incrementing numbers on each line.
Rather than having to type each line.

For example:
/~~~~~~~~~~~~
1
2
3
4
5
6
7
8
.....
\______________
up to whatever number?

Thanks
Kind regards.


--
............._..
.|  .| |.|/.|_ .
.|__.|_|.|\.|_ .
:61 421 276 282:
Reply | Threaded
Open this post in threaded view
|

Re: inserting 1 - 100 (numbers) on consecutive lines

Charles E Campbell Jr
Quoting [hidden email]:


> Is there a way to insert into vi with incrementing numbers on each line.
> Rather than having to type each line.

See http://mysite.verizon.net/astronaut/vim/index.html#VimFuncs and
check out "Visual Incrementing" and
http://vim.sourceforge.net/scripts/script.php?script_id=670.

There's also techniques using \r= and functions (see addenda to tip
http://vim.sourceforge.net/tips/tip.php?tip_id=150).

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: inserting 1 - 100 (numbers) on consecutive lines

Georg Dahn
In reply to this post by luke-44
Hi!

There is also a way doing this without any macros: let's assume, you
want to increment the numbers on each line up to 20. Then the following
will do the trick:

1. In the starting line write 1.
2. In the normal mode type qa which starts recording a macro into the
register a.
3. Type V for visual line selection.
4. Type y for yanking the line.
5. Type p for pasting the line.
6. Type Ctrl-A to add 1 to the number.
7. Type q to stop the macro.
8. Type 18@a to repeat the macro in register a 18 times.

Best regards,
Georg



[hidden email] wrote:

> Hi.
>
> Is there a way to insert into vi with incrementing numbers on each line.
> Rather than having to type each line.
>
> For example:
> /~~~~~~~~~~~~
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> .....
> \______________
> up to whatever number?
>
> Thanks
> Kind regards.
>
>

               
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: inserting 1 - 100 (numbers) on consecutive lines

Gerald Lai-2
On Mon, 6 Feb 2006, Georg Dahn wrote:

> Hi!
>
> There is also a way doing this without any macros: let's assume, you want to
> increment the numbers on each line up to 20. Then the following will do the
> trick:
>
[snip]
> [hidden email] wrote:
>> Hi.
>>
>> Is there a way to insert into vi with incrementing numbers on each line.
>> Rather than having to type each line.
[snip]

Many ways :) Georg explained the recording method. Here are a couple
more. Let's say you wish to number lines 22-31 with the numbers 1 to 10
at the beginning of the line.

# within Vim
:22,31s/^/\=line(".")-21

# if you have 'cat'
:22,31!cat -n

Hope this helps.
--
Gerald
Reply | Threaded
Open this post in threaded view
|

Re: inserting 1 - 100 (numbers) on consecutive lines

Yongwei Wu
In reply to this post by luke-44
If you are on a Linux/Unix box (or have Cygwin available), you may try:

yy
99p
:%!nl -ba

Check (in a shell) "nl --help" for options.  Using the ":%!nl" method,
you can insert the line numbers after you finish editing the file.

On 2/6/06, [hidden email] <[hidden email]> wrote:

> Hi.
>
> Is there a way to insert into vi with incrementing numbers on each line.
> Rather than having to type each line.
>
> For example:
> /~~~~~~~~~~~~
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> .....
> \______________
> up to whatever number?

Best regards,
--
Wu Yongwei
URL: http://wyw.dcweb.cn/
Reply | Threaded
Open this post in threaded view
|

Re: inserting 1 - 100 (numbers) on consecutive lines

luke-44
In reply to this post by Gerald Lai-2
Hi.

06Feb2006 @ 16:30 Gerald Lai thusly spake

> On Mon, 6 Feb 2006, Georg Dahn wrote:
>
> >Hi!
> >
> >There is also a way doing this without any macros: let's assume, you want
> >to increment the numbers on each line up to 20. Then the following will do
> >the trick:
> >
> [snip]
> >[hidden email] wrote:
> >>Hi.
> >>
> >>Is there a way to insert into vi with incrementing numbers on each line.
> >>Rather than having to type each line.
> [snip]
>
> Many ways :) Georg explained the recording method. Here are a couple
> more. Let's say you wish to number lines 22-31 with the numbers 1 to 10
> at the beginning of the line.
>
> # within Vim
> :22,31s/^/\=line(".")-21
>
> # if you have 'cat'
> :22,31!cat -n

Yes, this definitely helped especially the line function.
Thanks.

Kind regards.
Luke.





>
> Hope this helps.
> --
> Gerald

--
............._..
.|  .| |.|/.|_ .
.|__.|_|.|\.|_ .
:61 421 276 282: