Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 647
frank Avatar asked Nov 19 '14 18:11

frank


People also ask

How do I indent automatically in Sublime Text?

That's quite simple in Sublime. Just Ctrl+Shift+P (or Command+Shift+P on MacOS) to open the tools pallet, type reindent , and pick Indentation: Reindent Lines . It should reindent all the file you are in, just remember to save before running the command, or it may not appear.

How do I align codes in Sublime Text 3?

Simple: Select the lines you wish to align. Press Ctrl+Alt+A (Windows & Linux) or Command+Ctrl+A (Mac OS X)


1 Answers

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
like image 116
wolendranh Avatar answered Oct 29 '22 21:10

wolendranh