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)?
1 Answer
- 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
- Run the keyboard macro many e.g. 1000 times:
C-u 1000 M-x call-last-kbd-macro
kill-matching-lines
instead ofoccur
.