Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping comments with line breaks in PyCharm

I have comments that gets balloon (PEP 8: Line too long ... > 120) I wish there was a command that will wrap the lines with few keystrokes. Right now, even if I type Alt+Enter and press enter on Reformat file, nothing actually changes. Is there a setting or plugin I could use to accomplish the formatting easily?

like image 654
Forethinker Avatar asked Jun 19 '13 16:06

Forethinker


People also ask

How do you wrap a comment in PyCharm?

Click the Wrapping and Braces tab, and check the "Ensure right margin is not exceeded" checkbox. Now if you select a region of lines and then run the Code/Reformat Code... command, PyCharm will do its best to wrap the comments or code appropriately.

How do you wrap long lines in Intellij?

You can enable soft wrap for the editor with ⇧⇧ (macOS), or *Shift+Shift (Windows/Linux), for the Search Everywhere dialogue, and then typing in soft wrap. You can also go to Preferences/Settings > Editor > General to enable Soft Wraps for more file types by default.


2 Answers

Under the Edit menu, there is a Fill Paragraph option, which does what I believe you want. You can assign a key command to this in Preferences, under Appearance & Behavior -> Keymap (search for "fill").

Personally, I choose first stroke Esc, second stroke Q, because that's what I've always used in Emacs...

like image 165
Mike Avatar answered Oct 05 '22 23:10

Mike


Firstly, reformatting won't work, not in Python at least, where whitespace is important. PyCharm's "Wrap when typing reaches right margin" option is what you're looking for. Now this will not work when you copy and paste code, but in the places where it gives you trouble, just press enter, and it will work.

Screenshot of where to turn on PyCharm "Wrap when typing reaches right margin" option

like image 31
Games Brainiac Avatar answered Oct 05 '22 23:10

Games Brainiac