1

This in org mode. How do I get from

  • 1 to 2
  • 2 to 3

in as few keystrokes as possible? And, if possible, in reverse. I was hoping selecting Food's subtree and M-^ would do the job but what it does instead is delete subsequent lines.

1

* Food
    This is the body,
    which says something about the topic of food.

** Delicious Food
    This is the body of the second-level header.

** Distasteful Food
    This could have
    a body too, with
    several lines.

*** Dormitory Food

* Shelter
    Another first-level topic with its header line.

2

* Food
This is the body,
which says something about the topic of food.

** Delicious Food
This is the body of the second-level header.

** Distasteful Food
This could have
a body too, with
several lines.

*** Dormitory Food

* Shelter
Another first-level topic with its header line.

3

* Food
  This is the body,
  which says something about the topic of food.

** Delicious Food
   This is the body of the second-level header.

** Distasteful Food
   This could have
   a body too, with
   several lines.

*** Dormitory Food

* Shelter
  Another first-level topic with its header line.

Key bindings

3

From 1, 3 to 2

  • Select all text: C-x h
  • Remove indentation: M-x close-rectangle RET

(Although kind of a hacky use of close-rectangle.)

From 1, 2 to 3

  • Select all text: C-x h
  • indent-region: C-M-\

From 3 to 1

With point at start of buffer:

M-x replace-regexp RET ^ + RET <4 spaces> RET

1

C-x h C-M-\ goes directly from 1 to 3

The first part (C-x h) runs the command mark-whole-buffer, the second (C-M-\) runs indent-region.

You can go from 1 or 3 to 2 with C-M-% ^ + RET RET, that runs the command query-replace-regexp to replace any sequence of whitespaces at the beginning of line with nothing.

I don't know how to easily revert the change.

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.