Thursday, April 23, 2015

Wrapping docstrings/comments in PyDev

This is a nifty trick when working with PyDev...

When you're writing docstrings it's usually pretty annoying having to manually wrap the contents of the string to fix inside a proper number of columns: say your standard is 80 columns and you've just written 5 lines of comments to fit in that, then, you decide to edit and add something in the middle: there it goes: you have to reindent all the lines below so that the block is nice again.

Well, PyDev has an utility for that: put your cursor on that block and do Ctrl+2, W (i.e.: press Ctrl+2 and type the char W later on). Doing that will fix your comment block to fit in the number of columns available (note that it works for code in docstrings and comments alike).

To give an example, say you have the code below:


Just place the cursor in the block, use Ctrl+2, W and voila, you get:


Hope PyDev users enjoy the trick (aligning those manually is definitely on the annoying group).

As a note, to configure the number of columns to be wrapped to go to preferences > general > editors > text editors and change the 'print margin column'.

To finish, Ctrl+2 has other interesting things (if you just press Ctrl+2 and wait a bit, a popup with the options will appear).

3 comments:

Unknown said...

This is awesome, I'm just about to write up a bunch of docstrings now. This will save me a ton of time, and save my delete, and spacebar keys:)

Cheers

Use pydev all the time, love it thanks!

Anonymous said...

I would like to suggest an option to enable the reflow function as-you-type while in a docstring or comment.

Dennis

Fabio Zadrozny said...

@Dennis,

Please enter your suggestion to the PyDev tracker.