Sublime Forum

Sublime Text with Python Black formatter

#1

Hi, may I know how to use Black formatter so that it will auto format on save?
The docs:


I have installed the LSP server, what’s the next step for auto format on save?
Thanks in advance

0 Likes

#2

A more modern alternative for subblack is python-black. It formats documents on save by default and directly uses black within ST’s plugin_host. It doesn’t need langauge servers or anything else.

To enable format on save for LSP, checkout its "lsp_format_on_save" setting.

0 Likes

#3

Is it possible to do it without this package?

I’d like to use Black’s suggestion with LSP, now the only thing I’m lack of is maybe something to configure Sublime Text to use Black:

  1. As default formatter for python file
  2. Auto format by Black on save

This is quite easy on VSCode because there is a dropdown in the setting to choose the default formatter or can do something like:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}
0 Likes