0
votes

In org-mode I need to quickly copy content under a heading to the kill ring excluding the heading itself. I found the function org-copy-subtree, but it copies the entire subtree with the heading.

In the following example I would like to copy "Sample text line 1" and "Sample text line 2" when my cursor is somewhere in the "My Sample Heading 1":

* My Sample Heading 1
Sample text line 1
Sample text line 2
* My Sample Heading 2
Sample text line 3
Sample text line 4

Is there a way to do it?

2
It's just text, so you could mark the region and do M-w. - NickD

2 Answers

0
votes

This will return a substring of everything under the current headline. If you want to kill the contents directly, just replace buffer-substring-no-properties with kill-region.

(save-excursion
 (org-back-to-heading)
 (forward-line)
 (unless (= (point) (point-max))
  (let ((b (point))
        (e (or (outline-next-heading) (point-max))))
   (buffer-substring-no-properties b e))))
0
votes

I use org-mark-subtree then jy.