Emacs equivalent of Vim's yy10p?

Sard picture Sard · Sep 16, 2008 · Viewed 9.5k times · Source

How can I copy a line 10 times easily in Emacs? I can't find a copy-line shortcut or function. I can use C-aC-spcC-eM-w to laboriously copy the line but how can I then paste it more than once?

Any ideas before I go and write my own functions.

Answer

ljs picture ljs · Sep 16, 2008

you can use a keyboard macro for that:-

C-a C-k C-x ( C-y C-j C-x ) C-u 9 C-x e

Explanation:-

  • C-a : Go to start of line
  • C-k : Kill line
  • C-x ( : Start recording keyboard macro
  • C-y : Yank killed line
  • C-j : Move to next line
  • C-x ) : Stop recording keyboard macro
  • C-u 9 : Repeat 9 times
  • C-x e : Execute keyboard macro