Closed ghost closed 1 year ago
I agree that a read-only mode that can be toggled would be super useful, though I would prefer it to be a temporary state, and apply just to the current open document. So maybe it could work as haibison says when applied at a folder level, but be a temporary state when applied at an individual file level?
For me, something like an "editor.action.ToggleReadOnly" shortcut would be great. That would disable edits, and prevent saving of the currently open file. Ideally it would have some sort of obvious visual indicator as well, so if it's toggled accidentally the user will understand why they can't make changes.
Thank you @coe-jeubanks
I often review code, so I think making that option persistent across restarts is useful. But you and other people might like it as a temporary switch. So my idea to dev team is maybe we could have an option to switch between "persistent" and "temporary" modes?
One scenario is when opening multiple files at a time: read-only option should be "remembered", or the code reviewer will have to manually mark those files read only one by one. It sounds simple, but I used to work with Geany -- which has read only mode. When doing so (opening multiple files, then switching to each tab to mark the file read-only), and doing so every day, it feels that a switch would help me a lot.
So when you're in "code review mode," you don't need to have any other files open for editing at the same time (taking notes, etc.)? That was why I thought a read-only at the folder level would work for you--you could put all of your files you are reviewing into one folder, and open that folder in Code, marking it (perhaps permanently) read-only. Then you'd still be able to create and save documents into other folders at the same time you are reviewing the read-only files. Below is a mock-up of what I mean. In my example, all of the folders except Notes are toggled to read-only, and you could individually set files in Notes temporarily to read-only if you want to review them. Yet you would still retain the ability to create and update other files in Notes.
My typical use for read-only is when I'm editing one file and need to have a second one open for comparison or reference, but I don't want to inadvertently make any changes to the reference file. I used to use UltraEdit, which has a toggle-able read-only option for an open file.
I do hope they can create an enhancement that meets both of our needs!
I also would like option of setting read-only for an open file to prevent changes.
fyi @bpasero
Would really like this or something similar to it. eg. https://github.com/Microsoft/vscode/issues/12227
A command line argument to optionally open each file(s) as read only would be nice.
Throwing my support in for a command line option to open a file as read only. Would be really handy for my workflow
I would also like this on a file level and persistent. Alternatively, it could be a temporary setting that I could set on an open file.
I want to set it on babel transpiled output files. I sometimes open these to check where errors in the browser occurred, but only want to edit the original source files. This option would stop me from forgetting and accidentally editing the transpiled output.
Other issues that requests this feature #33823 #17670
The editor has an option readOnly
that would need to be exercised by the workbench => removing editor
label.
This would be very helpful
I too would like to see a command line option to open a file as read-only:
My use case:
I use file manager tools (e.g. Total Commander) to navigate through source files and have a need for opening files for read-only to just view the code without accidentally changing the code.
I previously used Notepad++ for editing and viewing source code, and this worked perfectly because Notepad++ have a command line option to open the file as read-only.
I have since switched to VS Code as an editor, and I really miss the option to call VS Code from the file manager and have VS Code open the file as read-only.
I prefer to use VS Code instead of Notepad++ as I'm working on different platforms and can have VS Code on all my platforms, but the missing read-only option in VS Code forces me to still have Notepad++ as my code viewer when I'm on Windows.
When will this feature be available?
Another use-case: when viewing application log files, I do not wish to accidentally change a file.
I need read-only mode for code-workspace's root-folders.
opening files (or folders) as read-only would be a great addition I would get a lot of use out of.
Would love to see this. I'm currently using vscode for debugging and vim for editing and sometimes I get my alt-tabs mixed up and end up editing files in vscode accidentally.
I remember long long ago Visual Studio had this. You could simply right-mouse click in the editor and there was an option to set the file to read-only. Actually, it didn't even set the file on disk to read-only, it was just in the editor.
Would love to see this in Visual Studio Code.
This could be useful for when the user opens a system file via go to definition or the debugger, e.g., a file in an installed Ruby gem.
Any updates? Would love this ability.
I found this request while trying to figure out how to mark a file read-only in the editor. I had two files open, one for reference and one that I was editing. Naturally I wound up editing the reference file and not the one I intended. It would be very helpful to be able to open a file, right-click and set a read-only/no-edit option for the open document.
One simple scenario: In my node app code base, I navigate to node_module
files a lot to read source code, but more than a few times that I found changing the files with mistaken finger typing. IntelliJ would make an alert for this. I'd like this feature available in vscode. Thank you very much.
I need readonly since I'm viewing a file's hexdump on VSCode but have to close out everytime I rerun it since two programs can't be writing to the same file.
Any updates on this feature?
I use Go language, and sometimes I would like to take a look at those built-in libraries. I need this feature to prevent modification on them. Any work on this will be appreciated.
I have looked far and wide for a solution to this! From a teacher standpoint, this feature is vital when demonstrating code on-screen with a range of 20-30 in-class students. Together with Visual Studio's Live Share, this feature is an absolute necessity!
+1 upvote for in-class setting
I would love this feature. I would want it to detect Unix file permissions and prevent the user from accidentally spending time editing files they don't have write permission for.
Are we there yet?
Is there any new state of update here? I'm using a source control in the way of lock/edit and commit. In this way of source controlling it is very important to recognize which files are read-only to lock them up befor change anything.
At the moment I do not need to lock them to have the possibility to change something. Result is, that somtime this ends up into a merge procedure, which I actually try to prevent by the kind of source control i use. I would be very pleased if this feature would be implemented.
For me, it mainly relates to my build output... I often peek at those files and it is all to easy to start editing the files, save, do a build, and overwrite my changes. From my perspective, it would be great to be able to list a file match pattern to treat as read only in the editor, e.g. dist-*/**
Adding a partial answer, see top answer here: https://stackoverflow.com/questions/30140112/how-do-i-hide-certain-files-from-the-sidebar-in-visual-studio-code files: exclude
Above is not a perfect solution but it does make me think hard if I want to open a built file, which is half the battle. But, it's disconcerting to not be able to see my built files easily.
@fischeme
easy to start editing the files, save, do a build, and overwrite my changes.
That's exactly my use case. Hiding them won't work because I want to debug with the built files, setting breakpoints and making use of the line numbers in error output. Several times I've accidentally edited the built files, only to have to copy the changes back to my source or just rewrite them.
I added a chmod command to my build script to prevent me from saving the changes and forgetting about it entirely, and I even installed a plugin to display a file's permissions in the status bar. But it still lets you type, and info in the status bar isn't exactly conspicuous.
So many use cases more than mine :D. In my case, I would like to edit a file while having few other files opened to refer from. Would love to have those reference files open in read-only mode. Any extensions that allow this? Did a quick search and couldn't find any on Marketplace
Not sure about windows users, but for Mac and Linux users. You could try the following:
cd my-project
chmod -R -w my-project # making it readonly
code my-project
Now VSCode would do something like this.
Of course, you can always change files permissions, later.
Cheers!
@ldong That notification is helpful when accidentally attempting to save. Many (myself included) might prefer that writing in the editor immediately triggers feedback if the user ultimately won't be able to save anyway. But I also wouldn't want to discard the current behavior for those that prefer that (allow changes until the user attempts to save, then notify).
Maybe we break it down into two features:
A "read-only" flag for each editor tab, to be set via the methods suggested in this thread (file explorer context menu, "code review mode" global toggle, commands, command line arguments, inference from file permissions, files listed in settings.json, ...)
Control over how read-only editors behave. (notify on save, notify on change, ignore input outright, ...)
There's something like a read-only flag in VSCode already: when the settings.json editor is open, the "Default User Settings" alongside it will ignore input and display a small message near the cursor: "Cannot edit in read-only editor". But (unless I'm missing something) there's no way for users to employ that behavior in other editors.
Another use-case: when viewing application log files, I do not wish to accidentally change a file.
up!
I really need this. Both detection of an os level set read-only and the possibility to toggle it if possible, but especially a user set read only flag that don't set the actual os level read-only flag but only the current editor buffer or what it's called in vscode terms ( Notepad++ style: "Main Menu->Edit->Set Read-Only", Emacs style: M-x read-only-mode), for reviewing log files, 3rd. party code, configuration files, etc... I.e. files that I don't want to edit directly, but have to be writable for external tools invoked by me. And a command line option for the current editor buffer version would be a blessing too.
I really need this for code review
It would be nice to have this feature for vendor and node_modules directory. In order to view the implementation of framework methods/classes. Right now I'm using chmod to modify the bits to remove write access.
echo "This script makes vendor read only for all users, even the owner";
find $(PWD) -type d -exec chmod 0551 {} \;
find $(PWD) -type f -exec chmod 0444 {} \;
I would appreciate this feature greatly, too.
The same here - it would be much helpful when we want to check existing code without changing them by accident
Throwing my support in for a command line option to open a file as read only. Would be really handy for my workflow
I agree. Would really like a command line option for read only.
I am looking forward to this API.
Because there are some files, we don't want users to modify it, such as node_modules
.
With this API, we can set it to read-only by extension.
This should improve the user experience
I would appreciate this feature greatly, too. Any update?
Does anyone think there's a way of doing this with extension. Is there a way to make an editor 'read-only' via the extension API? Or perhaps blocking a save?
I admit I haven't read all the comments above, as a potential option to earlier remarks, would it be an option to enable read-only on a file-by-file (and diredtory-by-directory too) level, but also have a setting to enable it as 'read-only by default' or 'read-write by default' ?
Therefore if I typically want to make one file read-only (or 'lock it' - maybe could involve VCS too), so I don't accidentally make changes to the wrong file, I leave the option as read-write by default, and lock one file or a directory as I need it. For the others above who would like a persistent setting for code review, they have read-only by default, and need to unlock any files they would like to edit before being allowed to change them.
I would love to have this feature as well (and I like the command line argument option) In my company, we'd like to use vscode to open python files in read-only mode without the possibility to "overwrite" it, so our linters would run and we can quickly review a python file without changing it by mistake. Also, this seems to already be available in vscode, for example when you "> Open Default Settings (JSON)", if you try to type anything, nothing happens but a popup showing up next to the cursor telling you you can't edit the file.
I also would like a read-only mode for the same reasons others have mentioned above.
This would be great for those who takes a lot of time reading code, to avoid writing by mistake.
I like the idea of a workspace configuration as in #12227. My main use case is that I will be providing multi-part documents with content spread over multiple files. Some of these files should be directly editable by clients but others should only be editable by automated processes (including VSCode extensions). Managing this through OS permissions is a pain, particularly since it has to run on multiple OS's and be manageable in the field by non-programmers. (I can't just hide the non-editable files, because they need to be available for viewing.)
For my use-case, which is the Flutter SDK, I can't set it read-only on the OS as it needs to be updated by me periodically through git.
Details:
This feature should be very useful for code reviewing. And I think it's not hard to implement.
Thank you,