I'm sure others will reply with functions etc to do this, but I tend to go for:
* Create a new file
* Enter '1' on the first line
* 'yy' (copy first line)
* '99p' (paste 99 times)
* Ctrl-V (visual block mode)
* G$ (select everything)
* :I (visual increment using Dr Chip's visincr.vim plugin [1])
Alternatively, just use perl:
perl -e 'for($i=1;$i<=100;$i++) { print $i . "\n"; }' > filename.txt
Of course...this is Vim so there regularly a multitude of ways to
accomplish a goal :)
> * Create a new file
> * Enter '1' on the first line
> * 'yy' (copy first line)
> * '99p' (paste 99 times)
> * Ctrl-V (visual block mode)
> * G$ (select everything)
> * :I (visual increment using Dr Chip's visincr.vim plugin [1])
I case you don't want to bother with plugins (I like to keep my
vim installs pretty native so I don't start leaning on things
that aren't baked-in across all the umpteen machines I use), you
can use
yy (yank the initial empty/blank line)
99p (paste it 99 more times to get places to put line#s)
:%s/^/\=line('.') (to put the current line# on each line)
> Alternatively, just use perl:
>
> perl -e 'for($i=1;$i<=100;$i++) { print $i . "\n"; }' > filename.txt
Or most *nix boxes have "seq" available:
:0r! seq 100
and optionally ":$d"/"Gdd" to delete the last/blank line
:)
-tim
In Vim7 you'd say for example
:put = range(1,100)
but in Vi ... are you sure you're using Vi and not Vim?
:ver
--
Andy
Indeed!
>
> > * Create a new file
> > * Enter '1' on the first line
> > * 'yy' (copy first line)
> > * '99p' (paste 99 times)
> > * Ctrl-V (visual block mode)
> > * G$ (select everything)
> > * :I (visual increment using Dr Chip's visincr.vim plugin [1])
>
> I case you don't want to bother with plugins (I like to keep my
> vim installs pretty native so I don't start leaning on things
> that aren't baked-in across all the umpteen machines I use), you
> can use
>
> yy (yank the initial empty/blank line)
> 99p (paste it 99 more times to get places to put line#s)
> :%s/^/\=line('.') (to put the current line# on each line)
>
>
> > Alternatively, just use perl:
> >
> > perl -e 'for($i=1;$i<=100;$i++) { print $i . "\n"; }' > filename.txt
>
>
> Or most *nix boxes have "seq" available:
>
> :0r! seq 100
> and optionally ":$d"/"Gdd" to delete the last/blank line
>
> :)
>
> -tim
>
>
>
> >
A pure Vimscript method that will work on boxes without Perl or seq
(I'm talking about you, WinXP):
:for i in range(1, 100) | exe "put =" i | endfor
--
Erik Falor
Registered Linux User #445632 http://counter.li.org
Insert a new line that contains the number 1.
qq (start recording)
yy (yank the line)
p (put the yanked line)
^A (increment the number under the cursor)
q (stop recording)
You will now have a file with 2 lines in it: 1 and 2.
Now the fun begins:
98@q (repeat the recorded macro [yank, put, increment] 98 times)
Dave