Search code examples
pythonvisual-studio-codevscode-code-runner

How to turn off run selected text in vscode


I want to turn off run selected text in vs code, but I don't know where's this option exactly.

For example in this code:

result = "Hello"

print(result)

If I accidentally selected the last 4 characters ult) by mouse and hit run, the output won't be "Hello", it will produce this error:

$ python -u "/home/irkoi/Documents/projects/Javascript/scripts/tempCodeRunnerFile.py"
  File "/home/irkoi/Documents/projects/Javascript/scripts/tempCodeRunnerFile.py", line 1
    ult)
       ^
SyntaxError: unmatched ')'

Notice: It creates a file called tempCodeRunnerFile.py and runs it, but this is not the file that I want to run.

I guess this may be because of the code runner extension, but this is the first time that it behaves this behavior.

Thanks for reading this issue, your help will be more than appreciated.


Solution

  • I know it's weird that I'm answering my question, but I discovered a solution.

    My solution was to modify the settings.json file property "code-runner.ignoreSelection", it has the value false by default, I set it to true.

    In details:

    • Click on the file menu, then choose preferences.

    • Go to settings and in the search bar, search for JSON

    • Untick the option Use Split JSON if it was ticked.

    • Click on Edit in settings.json.

    • put this line "code-runner.ignoreSelection": true in your settings.json file (before the last curly brace).

    I hope that helps anyone who encounters the same problem that I had.