Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Repeat count for yanking

561 views
Skip to first unread message

C K Kashyap

unread,
Jul 5, 2011, 5:35:38 AM7/5/11
to help-gn...@gnu.org
Hi,
How can I provide a repeat count to yank - 

I'd like to kill a line and then paste it 100 times - how can I achieve this?

Regards,
Kashyap

David Kastrup

unread,
Jul 5, 2011, 6:38:46 AM7/5/11
to
C K Kashyap <ckka...@gmail.com> writes:

> Hi,
>
> How can I provide a repeat count to yank -�
>
> I'd like to kill a line and then paste it 100 times - how can I
> achieve this?

C-x ( C-y C-u 100 C-x )

--
David Kastrup

Peter Münster

unread,
Jul 5, 2011, 7:13:39 AM7/5/11
to help-gn...@gnu.org
On Tue, Jul 05 2011, C K Kashyap wrote:

> How can I provide a repeat count to yank - 
>
> I'd like to kill a line and then paste it 100 times - how can I achieve this?

You can put the yank into a keyboard macro and use the prefix argument
to call the macro 100 times.

--
Peter


Richard Riley

unread,
Jul 5, 2011, 7:46:47 AM7/5/11
to help-gn...@gnu.org
C K Kashyap <ckka...@gmail.com> writes:

> Hi,


> How can I provide a repeat count to yank - 
>
> I'd like to kill a line and then paste it 100 times - how can I
> achieve this?
>

> Regards,
> Kashyap
>
>

I was looking at this recently.

http://stackoverflow.com/questions/71985/emacs-equivalent-of-vims-yy10p

ulp!


Perry Smith

unread,
Jul 5, 2011, 8:38:47 AM7/5/11
to help-gn...@gnu.org
If it is a one time thing, I usually do it in powers of two.  e.g. yank it maybe 4 times, then kill that and yank 4 times.  Now you have 16 lines.  ...

Remember that M-< sets the mark.  So if you narrow the region you can paste a lot of lines rather quickly.

If I was going to do this moderately frequently, I would toy around and learn how to do it via M-; (eval).  Seems like one line of lisp could do this.


Thierry Volpiatto

unread,
Jul 5, 2011, 8:44:43 AM7/5/11
to help-gn...@gnu.org
Perry Smith <ped...@gmail.com> writes:

M-: (loop repeat 5 do (progn (yank) (insert "\n")))

--
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997


Richard Riley

unread,
Jul 5, 2011, 1:09:59 PM7/5/11
to help-gn...@gnu.org
Thierry Volpiatto <thierry....@gmail.com> writes:

Or press C-y a few times ;)


Andreas Röhler

unread,
Jul 5, 2011, 1:27:23 PM7/5/11
to help-gn...@gnu.org

nice, and what about that:

(defun yank-repeat (&optional arg)
(interactive "p")
(dotimes (i arg)
(insert (car kill-ring))))


Teemu Likonen

unread,
Jul 5, 2011, 9:42:17 AM7/5/11
to Thierry Volpiatto, help-gn...@gnu.org
* 2011-07-05T14:44:43+02:00 * Thierry Volpiatto wrote:

> M-: (loop repeat 5 do (progn (yank) (insert "\n")))

Of course we include the newline in the last kill and do this:

M-: (dotimes (i 4) (yank))

Or use this:

(defun yank-repeatedly (n)
(interactive "NHow many times: ")
(dotimes (i n)
(yank)))

C K Kashyap

unread,
Jul 6, 2011, 2:26:39 AM7/6/11
to Teemu Likonen, help-gn...@gnu.org, Thierry Volpiatto
Thanks for all the lisp solutions - this is exactly why I have picked up emacs....

Regards,
Kashyap

Steinar Bang

unread,
Jul 21, 2011, 5:39:58 PM7/21/11
to help-gn...@gnu.org
>>>>> pml...@free.fr (Peter Münster):

> You can put the yank into a keyboard macro and use the prefix argument
> to call the macro 100 times.

That would be `C-x ( C-y C-x )' to define the macro (and as a side
effect do a single yank), and then `C-u 99 C-x e' to execute the macro
99 times (to get the remaining 99 yanks).

It's less effort than you might think, since creating a keyboard macro
for a repetitive task, is something you do frequently once you've
discovered it (at least I did).

Deniz Dogan

unread,
Jul 21, 2011, 5:41:28 PM7/21/11
to help-gn...@gnu.org

I advised `yank' so that C-u 100 C-y yanks 100 times instead (which is
much more useful in my opinion):

(defadvice yank (around damd-yank first nil activate)
"If ARG is neither nil nor \\[universal-argument], yank ARG times.
Otherwise, use the original definition of `yank'."
(if (or (not arg)
(consp arg))
ad-do-it
(dotimes (i arg)
(yank))))

Deniz

David Kastrup

unread,
Jul 23, 2011, 12:16:56 PM7/23/11
to
Steinar Bang <s...@dod.no> writes:

>>>>>> pml...@free.fr (Peter Münster):
>
>> You can put the yank into a keyboard macro and use the prefix argument
>> to call the macro 100 times.
>
> That would be `C-x ( C-y C-x )' to define the macro (and as a side
> effect do a single yank), and then `C-u 99 C-x e' to execute the macro
> 99 times (to get the remaining 99 yanks).

Easier to do C-x ( C-y C-u 100 C-x ) I think.

--
David Kastrup

0 new messages