Cannot edit in read-only editor VS Code

Visual Studio-Code

Visual Studio-Code Problem Overview


I am using Visual Studio Code V 1.31.1. I used an input function but I can't write an input in output panel it shows this error

>Cannot edit in read-only editor.

Please help me solve this problem.

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

  1. Go to File > Preference > Settings then
  2. type: run code and scroll down until you see code-runner: Run in terminal, There will be multiple options called "code-runner". In that you can find the option mentioned below.
  3. just check "Whether to run code in integrated terminal" and
  4. restart vscode.

For Mac users, it is Code > Preference > Settings.

Solution 2 - Visual Studio-Code

If you can't find where to find code runner as said in Ali NoumSali Traore's answer, here's what you got to do:

  1. Go to extensions (Ctrl + Shift + X)
  2. Find code runner and click on the settings icon on bottom right of the code runner
  3. Click configure extensions settings
  4. Find code_runner: Run in terminal
  5. Check "Whether to run code in terminal"

Solution 3 - Visual Studio-Code

I received this error during a code compare with previous version and it wasn't letting me edit the current version in the Right-Window. Unrelated to what I suspect OP's issue but this was the first thread that came up for my search and the error was the same. anyway...

My issue was that the particular file was 'Staged' in my source control at the time. This appears to restrict editing by opening an 'index' version for the compare.

Solution: Un-stage the file, and reopen the comparative window.

Solution 4 - Visual Studio-Code

You are in the "Output" tab instead of the Terminal. The output tab is actually only for you to read from.

enter image description here

Press F5 to begin Debugging and it'll bring you into the Terminal tab.

The terminal is interactive, so you can read output AND type back. It is indeed a console prompt/ terminal (hence its name).

enter image description here

Solution 5 - Visual Studio-Code

The easiest way to fix this was to press (CTRL) and (,) in VS Code to open Settings.

After that, on the search bar search for code runner, then scroll down and search for Run In Terminal and check that box as highlighted in the below image:

Solution 6 - Visual Studio-Code

Had the same problem. Here’s what I did & it got me the results I wanted.

  1. Go to the Terminal of Visual studio code.
  2. Cd to the directory of the file that has the code you wrote and ran. Let's call the program " xx.cpp "
  3. Type g++ xx.cpp -o a.out (creates an executable)
  4. To run your program, type ./a.out

Solution 7 - Visual Studio-Code

I was experiencing this issue while using the SFTP extension in VSCode. In this case, all you have to do is right-click somewhere in the file and select 'edit in local'

enter image description here

enter image description here

enter image description here

Solution 8 - Visual Studio-Code

I received the same error like @jgritten. Just like the comment before me by @jgritten, I 'unstaged' and reopened vscode and the files. Now I 'staged' it again. The error "Cannot edit in read-only editor" didnt come.

Hope this reassures anyone who might have similar error after staging the file using git in vscode.

Solution 9 - Visual Studio-Code

If your code takes input from a user you can't just use output tab. You have to use any terminal as Jordan Stefanelli have said.

  1. just go to terminal tab and select powershell or default terminal
  2. type python Nameoffile.py
  3. you will be able to input

Solution 10 - Visual Studio-Code

I had the Cannot edit in read-only editor error when trying to edit code after stopping the debug mode (for 2-3 minutes after pressing Shift+F5).

Turns out the default Node version (v9.11.1) wasn't exiting gracefully, leaving VScode stuck on read-only.
Simply adding "runtimeVersion": "12.4.0" to my launch.json file fixed it.

alternatively, change your default Node version to the latest stable version (you can see the current version on the DEBUG CONSOLE when starting debug mode).

Solution 11 - Visual Studio-Code

As the @Jordan Stefanelli answer: If you encounter the same problem as me that the integrated Terminal cannot read input from user as below hanging (env. Windows 10)

enter image description here

> my solution was to replace cygwin's gdb and g ++ with mingw64's.

then the input output are normal

enter image description here also you can enable "external console" option to solve it:) > you can change it by enabling "externalConsole":true in the launch.json then you will get a pop up console window that you can type in.

Solution 12 - Visual Studio-Code

Short Answer: After installing "Code Runner" extension, you just have to right-click the selected part of code you wish to execute and see it in the Output Tab.

Solution 13 - Visual Studio-Code

Click on the file and hover on Preferences. there you will find the first option as Settings and click on that. There search run code. and scroll and find the option code runner: Run in Terminal. now check the option below it

Solution 14 - Visual Studio-Code

I had the same problem, even though i enable the code runner to true, i was not still able to get my vsc terminal run. The quick fix was that mentioned by @Jordan Stefanelli. I add to my setting.json in the launch section "externalConsole":true,

"launch": {      
    "externalConsole":true,
    "configurations": [],
    "compounds": []
}

Solution 15 - Visual Studio-Code

Here's the easy way: Above your error "cannot edit in read-only editor" there will be a path to your cpp code file, it might look something like this if you are running on Linux:

cd "/home/jacksparrow/Documents/projects/" && g++ exams.cpp -o exams && "/home/jacksparrow/Documents/projects/"exams

so all you have to do is "copy(ctrl+shift+C) that path address and paste(ctrl+shift+V) it in the terminal window and press enter" right next to your output and debug console window. This worked for me, hope it does for you too.

Solution 16 - Visual Studio-Code

In VS Code, install code runner. When running your file please specify how you want to run the file, in the output window or terminal. For a better experience make sure you have selected the terminal.

Solution 17 - Visual Studio-Code

Solution 18 - Visual Studio-Code

if you are searcing for this in 2022 so you only need to RIGHT CLICK and click on EDIT local

Solution 19 - Visual Studio-Code

My issue was different than OP. I was trying to compare the file changes between commits. When I see some issue in diff view, I wasn't able to edit the file getting same message as OP. To fix that, instead of opening the file in diff view. Right-click on it and choose Open Changes > Open Previous Changes with Working File. This view will let you edit while comparing. Hope this helps.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAsifView Question on Stackoverflow
Solution 1 - Visual Studio-CodeA. TraoreView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeHarisView Answer on Stackoverflow
Solution 3 - Visual Studio-CodejgrittenView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeJordan StefanelliView Answer on Stackoverflow
Solution 5 - Visual Studio-CodeCodeStar GMView Answer on Stackoverflow
Solution 6 - Visual Studio-Codeuser11841857View Answer on Stackoverflow
Solution 7 - Visual Studio-CodeHappyHands31View Answer on Stackoverflow
Solution 8 - Visual Studio-CodeBrianView Answer on Stackoverflow
Solution 9 - Visual Studio-CodeMohamed FathallahView Answer on Stackoverflow
Solution 10 - Visual Studio-CodeAsafView Answer on Stackoverflow
Solution 11 - Visual Studio-Code傅继晗View Answer on Stackoverflow
Solution 12 - Visual Studio-CodeC G OView Answer on Stackoverflow
Solution 13 - Visual Studio-CodeVenugopal A BView Answer on Stackoverflow
Solution 14 - Visual Studio-CodeMohamed NourdineView Answer on Stackoverflow
Solution 15 - Visual Studio-CodeJack SparrowView Answer on Stackoverflow
Solution 16 - Visual Studio-CodeKimanthi K.View Answer on Stackoverflow
Solution 17 - Visual Studio-CodeNigilanView Answer on Stackoverflow
Solution 18 - Visual Studio-CodeMrRezaView Answer on Stackoverflow
Solution 19 - Visual Studio-CodeRaviView Answer on Stackoverflow