vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Add read-only mode

Open ghost opened this issue 9 years ago • 139 comments

  • VSCode Version: 0.10.11
  • OS Version: Fedora 23, 64bit

Details:

  • Please add read-only mode and its keyboard shortcut.
  • It should be a switch. When turned on, opening new files will be in read-only mode.
  • It should be persistent across restarts.

This feature should be very useful for code reviewing. And I think it's not hard to implement.

Thank you,

ghost avatar Apr 01 '16 23:04 ghost

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.

coe-jeubanks avatar Apr 15 '16 18:04 coe-jeubanks

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.

ghost avatar Apr 15 '16 18:04 ghost

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.

vs_ro_mockup

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!

coe-jeubanks avatar Apr 15 '16 19:04 coe-jeubanks

I also would like option of setting read-only for an open file to prevent changes.

Bill-Stewart avatar Sep 09 '16 20:09 Bill-Stewart

fyi @bpasero

alexdima avatar Sep 12 '16 11:09 alexdima

Would really like this or something similar to it. eg. https://github.com/Microsoft/vscode/issues/12227

rmchndrng avatar Sep 18 '16 18:09 rmchndrng

A command line argument to optionally open each file(s) as read only would be nice.

davenport avatar Nov 14 '16 14:11 davenport

Throwing my support in for a command line option to open a file as read only. Would be really handy for my workflow

ianelletson avatar Apr 18 '17 15:04 ianelletson

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.

gillez avatar Sep 28 '17 11:09 gillez

Other issues that requests this feature #33823 #17670

IanEdington avatar Sep 29 '17 18:09 IanEdington

The editor has an option readOnly that would need to be exercised by the workbench => removing editor label.

alexdima avatar Nov 23 '17 09:11 alexdima

This would be very helpful

cossio avatar Dec 11 '17 10:12 cossio

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.

chrjorgensen avatar Dec 23 '17 10:12 chrjorgensen

When will this feature be available?

ice1000 avatar Jan 15 '18 07:01 ice1000

Another use-case: when viewing application log files, I do not wish to accidentally change a file.

NorthboundTrain avatar Jan 28 '18 02:01 NorthboundTrain

I need read-only mode for code-workspace's root-folders.

boozook avatar Jan 28 '18 08:01 boozook

opening files (or folders) as read-only would be a great addition I would get a lot of use out of.

glaisne avatar Mar 27 '18 14:03 glaisne

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.

EverettBerry avatar Mar 30 '18 19:03 EverettBerry

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.

zethon avatar Apr 05 '18 16:04 zethon

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.

castwide avatar Apr 17 '18 16:04 castwide

Any updates? Would love this ability.

adenta avatar Jul 03 '18 18:07 adenta

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.

Whobeu avatar Jul 04 '18 15:07 Whobeu

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.

maomaobug avatar Jul 10 '18 09:07 maomaobug

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.

Graystripe17 avatar Jul 11 '18 12:07 Graystripe17

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.

universonic avatar Aug 02 '18 02:08 universonic

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

Mannilie avatar Aug 06 '18 11:08 Mannilie

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.

rmccreary avatar Oct 21 '18 00:10 rmccreary

Are we there yet?

osiixy avatar Oct 21 '18 14:10 osiixy

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.

kwegezed avatar Oct 22 '18 12:10 kwegezed

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 avatar Nov 01 '18 21:11 fischeme