How I can indent code block to align it to the beginning of #+BEGIN_SRC? Right now it looks like this:


And I would like to be like this:


1 Answer 1


Set org-src-preserve-indentation to nil and org-edit-src-content-indentation to 0.

org-src-preserve-indentation preserves the indentation of the source code in the src edit buffer that you get when you call org-edit-src-code on the source block also in the org buffer.

org-edit-src-content-indentation is the relative indent of the source code w.r.t. beginning of #+begin_src.

You can align existing source code by selecting a region containing the source code and pressing TAB. That key is bound to the command org-cycle and org-cycle calls the global binding for TAB if it does not find any special org stuff -- such as a headline -- on the current line.
If you edit the source code anyway you can also align the source code by:

  1. calling special edit on the source block via C-c ',
  2. aligning the source code in the source edit buffer such that it starts at the line beginning, (that is most probably done while editing the source code)
  3. returning to the org buffer by pressing C-c ' again.
  • @Drew You are right. I didn't address the actual question yet: How to align existing code w.r.t. #+begin_src. The settings given in the first version of the answer are important preconditions but they are not sufficient to align the text. I added two methods now.
    – Tobias
    Commented Jul 17, 2019 at 22:07

Your Answer

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

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