Home > Net >  How can I set "organize imports" to put each import on a new line
How can I set "organize imports" to put each import on a new line

Time:05-10

Instead of having imports from the same package on the same line I would like each import to be on a separate line to avoid merge conflicts. When I press Shift Alt O however, it puts all the imports on the same line between brackets. Is there a way to customise this shortcut so that it puts each import on a separate line?

e.g. instead of having

from typing import Dict, List, Tuple, Union

I would like to have

from typing import Dict
from typing import List

etc.

CodePudding user response:

Behind the scenes, Organize Imports for python uses isort. By looking at Sort Imports Args

Or you can manually add the entry in settings.json:

"python.sortImports.args": [
  "--multi-line",
  "7",
  "--sl"
]
  • Related