125

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.

5
  • seems you have no right to write this file, try to edit it in another editor.
    – pwxcoo
    Feb 25, 2019 at 3:06
  • You can't input data in output panel of VS Code since it read-only
    – Roshan
    Jun 11, 2019 at 16:27
  • Did you already find an answer to it @Asif?
    – PinkBanter
    Jan 30, 2020 at 15:47
  • By the way, you don't need to use F5 or CTRL F5 to run your code, you can just use the terminal instead.
    – crxyz
    Apr 14, 2021 at 1:12
  • If this error is showing with sftp extension skip to stackoverflow.com/questions/54856374/… below
    – wkille
    Jan 13, 2022 at 7:31

23 Answers 23

155
  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.

7
  • @RameshPareek in the search bar at the top.
    – EliadL
    Aug 12, 2019 at 9:13
  • 4
    Worked like charm - I just searched whether to run code in integrated terminal and got exactly one to check Sep 1, 2019 at 8:43
  • In macOS, click code>preference>settings, then type "code-runner" in the top search bar in the setting tab, and scroll down and check carefully, find the following option: code-runner: Run in terminal, tick the checkbox.
    – Carl Lee
    Sep 22, 2019 at 13:42
  • 9
    I can't find that setting
    – carlo
    Nov 25, 2020 at 12:15
  • 1
    @carlo this setting may not be findable, because it is for an extension, this is not standard vscode. And just in case, it runs code, it is not for debugging.
    – Dan Ortega
    Apr 28, 2021 at 23:01
28

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"
2
  • 11
    I didn't have code runner, but installing it didn't solve the problem anyway
    – carlo
    Nov 25, 2020 at 12:16
  • Also, Settings [Ctrl + , ] -> Checkbox Code-runner: Save All Files Before Run Dec 31, 2022 at 17:43
14

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.

3
  • 3
    @Roshan Op was unable to write and received this error. I even mentioned it was unrelated, but the error was the same so I added my 2 cents. take it or leave it
    – jgritten
    Jun 11, 2019 at 17:49
  • 2
    exactly my problem, thanks for your 2 cents Dec 20, 2021 at 6:45
  • exactly my problem, thanks for your 2 cents Apr 15, 2022 at 13:27
13

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

7

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:

5

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

1
  • It only edits the local file, it does not edit the file on server.
    – Neo
    Dec 30, 2022 at 18:06
4

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

1
  • I also have same problem in 1.74.1 and I do not have option to open with Workng file. What are they doing? It was a great feature to be able to edit when comparing. I could select ranges and do right click and do "Revert selected ranges", the Options in the context menu are there but do not work. That was a killer feature of VSCode which was missing in Visual Studio. Mar 1, 2023 at 18:18
3

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
2

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.

2

For Jupyter Notebooks / Interactive Code Cells Debugging:

When you run Debug Cell, you may notice that you sometimes can't edit after stopping the debug process.

As silly as it sounds, check your open file tabs.

The debugger appears to open a read-only copy that is separate from your working file w/ the same name.

1

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
1

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).

0

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.

0

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.

0

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

0

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": []
}
0

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.

0

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.

0

I installed the https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner and it started working for me.

2
  • You are only saying thanks for this existing answer, aren't you? stackoverflow.com/a/67503385/7733418
    – Yunnosch
    Apr 6, 2022 at 17:24
  • installed code-runner v.0.12.0 in vscode v1.74.1. Doesn't help. The change comparison editor in readonly mode anyway and can not edit and from context menu command "Revert selected ranges" doesn't work. But that "Revert selected ranges" was a killer feature of VSCode Mar 1, 2023 at 18:45
0

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

1
0

In my case file encoding types was in utf-8 with bom enter image description here

By opening in any text editor (I have used visual studio code but you can use any other text editor) and save with utf-8 will open file in edit mode and hit the debugger as well

0

I ran into the problem when following Prag Programmer's Phoenix Live View tutorial. The setup section of the tutorial says to do this:

Simple Ruby ERB extension for toggling <%= %> EEx tags using the custom keybindings you'll find in the vscode/keybindings.json file of the code bundle. To add these keybindings, use the "Preferences: Open Keyboard Shortcuts (JSON)" command and paste the contents of keybindings.json into that file.

When I clicked on View > Command Palette then entered Preferences: Open Keyboard Shortcuts (JSON) that opened up a Default keybindings file:

[
{ "key": "escape escape",         "command": "workbench.action.exitZenMode",
                                     "when": "inZenMode" },
{ "key": "shift+escape",          "command": "closeReferenceSearch",
                                     "when": "inReferenceSearchEditor && !config.editor.stablePeek" },
{ "key": "escape",                "command": "closeReferenceSearch",
                                     "when": "inReferenceSearchEditor && !config.editor.stablePeek" },
{ "key": "escape",                "command": "editor.closeTestPeek",
                                     "when": "testing.isInPeek && !config.editor.stablePeek || testing.isPeekVisible && !config.editor.stablePeek" },
{ "key": "shift+escape",          "command": "cancelSelection",

...
...
...
                  

But, I can't paste anything into that file because I get the message:

Cannot edit in read only editor.

I checked out the VS Code manual on Advanced Customization, which says:

enter image description here

Unfortunately, the icon for the Keyboard Shortcuts editor, the one with the green rectangle around it, was nowhere to be found. I was able to get that icon to display using the menu bar:

Code > Preferences > Keyboard Shortcuts

That brought up a page that looked like this:

enter image description here

If you look closely, up in the right hand corner is the icon for the Keyboard Shortcuts editor. I clicked on the icon, and that opened up a keybindings.json file, which looked like this:

// Place your key bindings in this file to override the defaults
[

]

...and I was copied the recommended key bindings:

{
  "key": "shift+cmd+,",
  "command": "erb.toggleTags",
  "when": "editorTextFocus && editorLangId == phoenix-heex"
},
{
  "key": "shift+cmd+,",
  "command": "erb.toggleTags",
  "when": "editorTextFocus && editorLangId == elixir"
}

and pasted them into that file, giving me this:

// Place your key bindings in this file to override the defaults
[
    {
        "key": "shift+cmd+,",
        "command": "erb.toggleTags",
        "when": "editorTextFocus && editorLangId == phoenix-heex"
      },
      {
        "key": "shift+cmd+,",
        "command": "erb.toggleTags",
        "when": "editorTextFocus && editorLangId == elixir"
      }
]
0

This solved the issue for me:

Go to File > Open Folder... and open your project folder again.

Not the answer you're looking for? Browse other questions tagged or ask your own question.