0

Let's say I want to move all the lines in a buffer that contain the string 'global' to the end of that buffer. If I use Emacs occur it produces an occur buffer with the lines I need, but also includes line numbers at the beginning of each line. If I then use rectangle-mark-mode I can cut these lines, switch back to the original buffer, move to the end and yank. I am then left with blank lines in the original buffer, which need to be removed. Is there an easier and cleaner way to move lines containing a string to the end (or beginning of a buffer)?

2
  • 2
    I would use kill-matching-lines instead of occur.
    – NickD
    Jan 28 at 15:04
  • I knew there had to be an easier way! Awesome!
    – Edman
    Jan 28 at 15:08

1 Answer 1

1
  1. Create a keyboard macro that: 1.1. Search for the keyword 1.2. cut the line 1.3. Mark the location in a register 1.4. Go to the end of the buffer 1.5. Paste the line 1.6. Go to the location marked in a register
  2. Run the keyboard macro many e.g. 1000 times: C-u 1000 M-x call-last-kbd-macro

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.