Skip to content

Refactoring: Sort Imports

Don Jayamanne edited this page Oct 3, 2017 · 3 revisions

How to invoke the Sort Imports command?

There are a three options to invoke the sort imports command, they are as follows:

Option 1 (Command Palette)

  • Launch the Command Palette via the shortcut (⇧⌘P or Ctrl+Shift+P)
  • Select the 'Sort Imports' command

Sample

Option 2 (Quick Fix)

  • Launch the Quick Fix command from the Command Palette (or use the short cut ⌘. or cmd+.)
  • Select the 'Sort Imports' command from the menu

Launching the Quick Fix command from the Command Palette
Sample using Quick Fix Command

Launching the Quick Fix command using the keyboard shortcut
Sample using Quick Fix Short Cut

Option 3 (Keyboard Shortcut)

  • Setup a custom keyboard short cut for the command 'python.sortImports'
  • Open a python file
  • Invoke the above command using the designated keyboard shortcut

Configuration

Sorting is performed using the isort package.
The sort behaviour can be configured by using the relevant isort configuration settings (https://github.com/timothycrosley/isort#configuring-isort).

Clone this wiki locally