microsoft / PTVS

Python Tools for Visual Studio
https://aka.ms/PTVS
Apache License 2.0
2.52k stars 673 forks source link

Inconvenient Behavior with Enter Key in Python #7911

Closed vsfeedback closed 1 month ago

vsfeedback commented 1 month ago

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice] When using the Enter key in Python editor, there is inconvenient behavior that differs from C# editor. In Python, pressing Enter adds spaces on a new line, whereas in C#, this does not occur. This creates inconvenience and complicates code editing. I constantly have to manually remove these spaces.

Steps to Reproduce the Issue:

Watch the attached video for a visual demonstration:

Expected Behavior: Pressing Enter should not automatically add spaces on a new line, as observed in the Python editor. The behavior should match that of the C# editor.

Explanation of the Issue: The problem leads to the following undesirable consequences:

  1. Pressing the backspace key adds spaces to the end of the previous line, which can distort the intended formatting of the code.
  2. The constant appearance and disappearance of spaces create more differences in code versions (Git), leading to frequent code merges and conflicts.
  3. This behavior complicates code editing and readability, making it harder for developers to maintain and collaborate on projects effectively.

Original Comments

Feedback Bot on 5/12/2024, 07:55 PM:

(private comment, text removed)


Original Solutions

(no solutions)

StellaHuang95 commented 1 month ago

Hi there, thanks for your issue. In Python, indentation is used to define the structure of code blocks, such as loops, conditional statements, and function definitions. Incorrect indentation can lead to syntax errors or alter the logic of your code.

In C#, indentation is not required for the compiler to understand the structure of your code, as it uses curly braces {} to define code blocks.

But that said, you can still disable smart indentation by going to Options -> Text Editor -> Python -> Tabs and turn off the indenting there.