question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve auto-indentation behaviour

See original GitHub issue

Environment data

VS Code version: Version 1.19.0 Commit 816be6780ca8bd0ab80314e11478c48c70d09383 Date 2017-12-14T09:56:48.842Z Shell 1.7.9 Renderer 58.0.3029.110 Node 7.9.0 Architecture x64

Python Extension version: 0.9.1 Python Version: Python 3.6.3 OS and version: ArchLinux

Case 1

The cursor is at | position (about to add second argument to print), and I press Enter:

Actual

def case1():
    print('first_argument', |)

It becomes:

def case1():
    print('first_argument', 
    |)

Expected 1

def case1():
    print('first_argument'
        |)

OR Expected 2 (this one is preferred)

def case1():
    print('first_argument'
          |)

Case 2

Actual

The cursor is right after the closing parenthesis and I press Enter.

def case2():
    print(
        'some_very_very_very_very_long_function_argument_',
        'second_argument')|

It becomes:

def case2():
    print(
        'some_very_very_very_very_long_function_argument_',
        'second_argument')
        |

Expected

def case2():
    print(
        'some_very_very_very_very_long_function_argument_',
        'second_argument')
    |

Case 3

Actual

The cursor after the comment. Press Enter:

def case3(): # some comment|

It becomes:

def case3(): # some comment
|

Expected

def case3(): # some comment
    |

Same with comments after for loops:

def case3(): # some comment
    for i in range(1): # another comment|

after pressing Enter becomes

def case3(): # some comment
    for i in range(1): # another comment
    |

Expected:

def case3(): # some comment
    for i in range(1): # another comment
        |

Also look at #3284

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:275
  • Comments:65 (11 by maintainers)

github_iconTop GitHub Comments

22reactions
gasteigerjocommented, Apr 17, 2018

I agree with case 1. It makes sense to have the default indentation behavior comply with PEP8 (https://www.python.org/dev/peps/pep-0008/#indentation).

20reactions
kbrosecommented, Mar 28, 2019

I’ve published a package that provides better python indentation. It’s still pretty immature, but has been working well for my purposes. https://marketplace.visualstudio.com/items?itemName=KevinRose.vsc-python-indent

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I change the behavior of Code::Blocks auto-indent?
First, make sure smart indent is enabled (Settings -> Editor -> Smart indent). It still wasn't working for me on Ubuntu, but installing...
Read more >
Improve Comments and Auto-format behaviour - Katalon Studio
Improve Comments and Auto-format behaviour · 1. Creation of multiline comments for reports · 2. Improve auto formating · 3. Auto format for...
Read more >
incorrect auto-indent behavior - Vi and Vim Stack Exchange
In some very specific scenarios, the auto indenter has almost unexplainable behavior that is very annoying. Example with haskell MultiWayIf ...
Read more >
Change behaviour of auto indenting inside html and body tag
Yes, Marek, you can. Go to Settings|Code Style|HTML. In "Do not indent children of" just remove the "body" tag. That should be it....
Read more >
Auto and Smart Indenting - Learning the vi and Vim Editors ...
Auto indentation closely mimics vi 's autoindent . It differs subtly as to where the cursor is placed after indentation is deleted. smartindent....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found