frank
frank

Reputation: 1342

Sublime Text Auto-Indent Python Keyword Arguments

I'm having an issue making Sublime act the way I like with keyword arguments. PEP-8 allows for two conventions for function calls:

function_name(
    arg=1,
    arg2=blah)

And:

function_name(arg=1,
              arg2=blah)

I much prefer the latter for lines less then 80 characters. but Sublime Text 3 doesn't accommodate that well. When I hit Enter after the first line comma, indentation continues four spaces in:

function_name(arg=1,
    arg2=blah)

Is there a way to get the editor to align the cursor to the position just right of the open parenthesis?

Thanks!

Upvotes: 6

Views: 3447

Answers (2)

Sayan Biswas
Sayan Biswas

Reputation: 189

Specifically for python 3.x

Tools->Command Palette-> Indentation: Convert to tabs

The entire file indentation will be converted to tabs from inconsistent indentation of tabs and spaces.

Upvotes: 0

wolendranh
wolendranh

Reputation: 4292

You need to change Sublime Text Preferences.

  1. Open Preferences
  2. Settings -> User
  3. Add this line there:
{"indent_to_bracket": true}
  1. Restart Sublime

After this you code will be formated in this way:

def function(*arg, 
             **kwargs):
    #body

Upvotes: 16

Related Questions