How to copy multiple lines from a buffer to another in Emacs?

I have two buffers. I want to copy lines 2, 5, 9 and 10 in the first buffer to the second buffer (just add the second buffer). With the exception of the copy and one line at a time, is there an elegant way to do this?

+4
source share
4 answers

A simple solution would be to write a macro that copies a line from one buffer to another ( f3 C-SCP C-n M-w C-x o C-y C-x o f4), and then executes a macro ( f4) on each line that you want to copy.

If this is a repeating scenario for you, you can save the macro and bind it to a key.

+3
source

append-next-kill, C-M-w, . M-w, :

  • 2: C-SPC, C-n, M-w
  • 5
  • - : C-SPC, C-n, C-M-w, M-w
  • 9...

... ..

C-y, .

+4

multiple-cursors.el. , / , .

https://github.com/magnars/multiple-cursors.el

/ add:

mc/add-cursor-on-click

, ( "" ):

(global-set-key (kbd "C-S-<mouse-1>") 'mc/add-cursor-on-click)

, , mc/add-cursor-at-line:

(defun mc/add-cursor-at-line (&optional linenum)
  (interactive "nLine number: ")
  (save-excursion 
    (goto-char (point-min))
    (forward-line (1- linenum))
    (mc/create-fake-cursor-at-point))
  (mc/maybe-multiple-cursors-mode))

, :

: C-SPC C-e M-w RET

...

Yank: C-x r y

+3

, , , , .

  • 1. ,
  • 2. C-space ,
  • 3. ,
  • 4. M-w
  • 5. C-x b RET
  • 6.
  • 7. C-y ()
  • 8. C-x C-x .
  • 9. C-n , .
  • 10. C-k C-k
  • 11. 9

, 9. 11. - :

  • 9.
  • 10. C-space ,
  • 11.
  • 12. C-w
  • 13. goto 9
0

All Articles