Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code creates new lines when using refactoring variables tool (F2) in Python

this is a pretty simple question but I couldn't figure out the solution for this problem.

The Problem

Let's say I have this simple Python code in VS Code IDE: enter image description here

Let's say I want to refactor the variable "value" to be "value1", I press Fn+F2 on my computer and I edit the variable name: enter image description here

This is the result of the code after the refactor step. enter image description here


As you can see it adds automatically a new line without me requesting something like that.

How I tried to solve this problem before asking here

I tried to search for a solution at Google, for example:

  1. VS Code creates empty lines after refactoring a variable in Python
  2. F2 refactor step creates new lines in VS Code, how to fix? And some more searches at Google but nothing helped...

There was some thread at Stack Overflow which said to click "Ctrl+Shift+P" and to open the "editor" and search for the solution there but unfortunately it didn't help.

I searched at VSCode official docs but I couldn't figure how where to search for this specific problem so I kinda got lost there.

My Extentions: enter image description here

The solution should be really easy but I miss something. I will be for your help, thanks! :)

like image 297
Moshe Binieli Avatar asked Nov 21 '25 17:11

Moshe Binieli


2 Answers

Just encountered the same issue, with the same extensions installed. This appears to caused somehow by line-endings.

When using CRLF line endings I can reproduce the behaviour you've described (the option should appear in vscode at the bottom right of the window). Switching this to LF, I get refactoring working as normal.

like image 76
Michael S Avatar answered Nov 24 '25 05:11

Michael S


For me the issue started when I disabled the Pylance extension.

Enabling the Pylance extension, then closing and reopening VSCode, got rid of the issue.

The role of Pylance is also mentioned in this GitHub issue.

like image 27
philipnye Avatar answered Nov 24 '25 07:11

philipnye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!