1

I frequently have a situation where I'll write a paragraph in a docstring for a function, then come back later and want to add to some part of the middle of the paragraph, and that will make me have to re-adjust the rest of the lines to have them be the proper length (not too long, not too short). This feels like something that should have an automation available for it.

I guess the trickiest part would be that the plugin would need to understand when to take words off of one line and add them to the beginning of the next line.

Is there some plugin or built-in action that will do this for me?

5
  • This doesn’t really answer the pycharm plug-in question, but Python’s builtin textwrap module is great for doing exactly this kind of formatting.
    – Samwise
    Jun 4 at 17:00
  • @Samwise if there's an easy way (e.g. not needing to write code) to use that to format the docstring, I'd accept that as an answer. Jun 4 at 17:39
  • The only automated tool I can think of is the option in PyCharm which automatically wraps the text after the line length reaches certain number of characters; It is available under Code Style settings (Hard wrap at & Wrap on typing). However, this setting is applied on everything (code included), not just docstring. Alternatively, you can select the docstring and format it using Edit -> Fill paragraph Jun 4 at 19:32
  • @mcvincekova Edit -> Fill paragraph does exactly what I was looking for. If you want to post it as an answer I'll accept/upvote it, otherwise I'm going to post the answer myself. Jun 4 at 20:12
  • @NathanWailes Sorry for the delay, posted. Glad it worked for you. Jun 9 at 14:24

1 Answer 1

1

You can select the docstring and format it using Edit -> Fill paragraph.

Alternatively the only automated tool I can think of (in Pycharm) is the option which automatically wraps the text after the line length reaches certain number of characters; It is available under Code Style settings (Hard wrap at & Wrap on typing). However, this setting is applied on everything (code included), not just docstring.

Your Answer

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

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