This is an example function that shows that docstrings do not automatically indent.

def testing_docstring():
docstring is not indented automatically!
Even after a newline.

Selecting a region inside the docstring and hitting tab won't work either. Only hitting tab on a single line will toggle the indent level. How can I set docstrings to automatically indent?


elpy has a function elpy-open-and-indent-line-below which is binded to <S-return>.

After """, you can hit <S-return> to open new line and indent automatically. You can use this at the end of line.

Alternatively, you can bind return to this function.

(define-key elpy-mode-map (kbd "<return>") 'elpy-open-and-indent-line-below)

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.