Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm PEP8 on save

Tags:

pep8

pycharm

So I have googled, I have SO'd, I have tried...

How can I get PyCharm to do PEP8 auto format as an on save action?

I found that I can do Ctrl+Alt+L to do auto formatting. I got used to having that as on save action on eclipse, so I'd like that in PyCharm. It was easy to do in GoGland, so why not in PyCharm?

I'm lost, please help...

like image 217
kratenko Avatar asked Jun 11 '17 12:06

kratenko


1 Answers

So what worked for me was roundabout but I haven't found an easy built in option to do this. My solution was to record a macro of format and save and then reassign the ctrl+s keybinding to that macro.

To make the macro: - Edit>Macros>Start Recording - Run ctrl+alt+L and then ctrl+s - Edit>Macros>Stop Recording>call it something like save and format

To reassign ctrl+s: - Settings>Keymap>Macros: - Select your macro and 'Add Keyboard Shortcut' and enter ctrl+s - Opt to remove it from save since your macro does that anyway

Documentation that goes into more detail: https://www.jetbrains.com/help/pycharm/recording-macros.html https://www.jetbrains.com/help/pycharm/binding-macros-with-keyboard-shortcuts.html

like image 175
Ian Later Avatar answered Nov 20 '22 19:11

Ian Later