Asif
Asif

Reputation: 1648

Cannot edit in read-only editor VS Code

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.

Upvotes: 129

Views: 344144

Answers (26)

Tamir Nakar
Tamir Nakar

Reputation: 1053

I just encountered this issue, and the solution was in my worktree.

Go to the Source Control tab and check if there's an action that is still in progress. In my case, I had left a dialog open after VS Code asked whether the files I marked as "skip worktree" belonged to my main repository or a submodule.

VS Code can sometimes be a bit inconsistent when handling unfinished tasks—it tends to throw the user into read-only mode instead of preventing him from proceeding until the operation is completed.

So, if you're facing this issue, make sure no pending dialogs or incomplete actions are blocking the process.

hope it helps

Upvotes: 0

Erik
Erik

Reputation: 485

On windows 11, I needed to:

  1. Go to File > Preferences > Settings.
  2. Search for workbench.editor.enablePreview.
  3. Disable it by unchecking the box.

I did not find anything related to code runner, that the other answers talked about.

Upvotes: 0

Jose Paez
Jose Paez

Reputation: 847

Easy and Quick Fix

Had similar issue, it took me a while to figure it out but in my case I basically clicked on the wrong thing.

In the Source Control tab of VSCode (third icon, selected in left panel, see screenshot), I had some changes:

  • Ones that were unsaved (in Changes folder).
  • Other changes I already saved and committed and pushed (in Outgoing folder, in Add.. folder with green and red icons).

I kept trying to work by clicking in the second ones (with the green and red icons) and trying to modify that file but that one is for reference in VSCode.

As soon as I clicked the first ones with the name of the file in the Changes folder I was back on editing mode 👍🏼

Hope this was helpful, hope you guys have a great day!

Screenshot of VSCode in the Source Control tab

Upvotes: 0

Benyamin
Benyamin

Reputation: 1154

This solved the issue for me:

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

Upvotes: 0

7stud
7stud

Reputation: 48609

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"
      }
]

Upvotes: 0

Ankit
Ankit

Reputation: 1214

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

Upvotes: 0

Ed Shelton
Ed Shelton

Reputation: 331

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.

Upvotes: 2

Ravi
Ravi

Reputation: 301

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

Upvotes: 4

MrReza
MrReza

Reputation: 1

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

Upvotes: 0

Nigilan
Nigilan

Reputation: 806

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

Upvotes: 0

Kevin Kyei
Kevin Kyei

Reputation: 585

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.

Upvotes: 0

Jack Sparrow
Jack Sparrow

Reputation: 33

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.

Upvotes: 0

Mohamed Nourdine
Mohamed Nourdine

Reputation: 1

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

Upvotes: 0

Venugopal A B
Venugopal A B

Reputation: 1

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

Upvotes: 0

C G O
C G O

Reputation: 51

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.

Upvotes: 0

GM&#39;s
GM&#39;s

Reputation: 133

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:

Upvotes: 7

Asaf
Asaf

Reputation: 8216

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

Upvotes: 1

HappyHands31
HappyHands31

Reputation: 4101

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

Upvotes: 5

A. T
A. T

Reputation: 1844

  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.

Upvotes: 160

Don Feto
Don Feto

Reputation: 1514

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

Upvotes: 1

Haris
Haris

Reputation: 351

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"

Upvotes: 29

傅继晗
傅继晗

Reputation: 1137

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.

Upvotes: 0

Jordan Stefanelli
Jordan Stefanelli

Reputation: 1494

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

Upvotes: 13

user11841857
user11841857

Reputation:

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

Upvotes: 3

Brian
Brian

Reputation: 55

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.

Upvotes: 2

jgritten
jgritten

Reputation: 1023

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.

Upvotes: 15

Related Questions