Automatically add newline on save in PyCharm?
Question:
Answers:
What I usually do is I create a macro to do three things:
- Reformat code
- Organise imports
- Save all files
This will, indeed, add a newline at the end of each file.
Then I rebind the Save all
shortcut (Cmd+S
on Mac) to this macro.
You can read more about macros here. I also recommend using Navigate to Action to find actions you forget the hotkeys for.
Here is how I found it in PyCharm Community Edition 2017.5. You can go to Preferences...
and do a search for ensure line feed
. Under Editor/General
the Other
option may not be visible as can be seen here:
But if you do a search, it finds it:
Hope it helps. Cheers!
This should be a default feature but if it is not enabled:
go to settings > Editor > General
then you will see a checkbox option to select…
PyCharm 2021.1
You can now find this setting here:
Settings
> Editor
> General
> Ensure every saved file ends with a line break
.
What I usually do is I create a macro to do three things:
- Reformat code
- Organise imports
- Save all files
This will, indeed, add a newline at the end of each file.
Then I rebind the Save all
shortcut (Cmd+S
on Mac) to this macro.
You can read more about macros here. I also recommend using Navigate to Action to find actions you forget the hotkeys for.
Here is how I found it in PyCharm Community Edition 2017.5. You can go to Preferences...
and do a search for ensure line feed
. Under Editor/General
the Other
option may not be visible as can be seen here:
But if you do a search, it finds it:
Hope it helps. Cheers!
This should be a default feature but if it is not enabled:
go to settings > Editor > General
then you will see a checkbox option to select…
PyCharm 2021.1
You can now find this setting here:
Settings
> Editor
> General
> Ensure every saved file ends with a line break
.