3

I have an org-mode file containing a structure like this:

*** H1
**** H2
- Foo
  Foo
**** H2
Foo

Foo

I would like to make a copy of H1 and all it's subheadings, but none of the non-headline content. I would then like to be able to paste this copy, adding the following content to the file:

*** H1
**** H2
**** H2

Currently the way I do this is to collapse H1 using yy (I use evil-mode), move to the appropriate place, with p, and then manually delete all the non-headline content.

How can I copy+paste org-mode headlines only?

5
  • Are you comfortable or have you considered keyboard macros?
    – aadcg
    May 26 at 12:29
  • Assuming you have two org buffers, and the cursor is on the "old" org file, you'd need to define a keyboard macro (F3; C-SPC; C-e; M-w; C-x o; C-y; C-e; RET; C-x o; C-c C-n; F4.). Then you can just call this macro with C-x e.
    – aadcg
    May 26 at 12:42
  • If you are doing this a lot, then consider writing up an org-mode custom function that narrows to the subtree desired and visits each headline in that narrowed section to gather what is needed, modifying the structure if needed, and place the result in the kill-ring. If you are doing this only occasionally, then the multiple-cursors package can do this in just a couple of moves -- i.e., narrow to subtree, select the stars (select all like this), move to the far left, select from there to the far right, and copy, and exit, then go to a new buffer and type C-x r y and there you go.
    – lawlist
    May 26 at 13:59
  • 1
    Already answered there: stackoverflow.com/questions/3193985/… if you accept outline-hide-leaves as first step.
    – Tobias
    May 26 at 14:30
6

org-copy-visible, bound to C-c C-x v, does this: collapse your outline until just the headings you want to copy are visible, set a region around them, and copy via org-copy-visible.

1
  • 1
    Thank @Tyler, and using org-mark-subtree to set the region makes things even easier. May 26 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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