I want to view some code files with VS Code and edit my own code to call them. I shouldn't change them (include the file mode) so it's best if I open those files in read-only mode.
In fact, I have met some trouble because of the modification by accident. So I think I should view those files in a safer way.
How to do it with VS code? I know PyCharm and Notepad++ have implented this function, so has VS Code? I haven't find it even on its official website.
Many thanks.
According to Visual Studio Code Feature Request #99322, https://github.com/microsoft/vscode/issues/99322, this feature will not be implemented in VSCode. However the extension "Read-Only Mode Support" Attempts to implement some read-only functionality, but is not ideal. It appears to require modification of config files to automatically ignore edits, but with files outside of the root directory, it offers a popup to ignore changes when you save.
You can make the file read only in the file system.
Linux:
chmod -w filename
For Windows, from File Explorer, right click file, select Properties, then Read Only.
Then each time you modify the file VSCODE warns you "Failed to save 'filename': File is read-only. Select 'Overwrite' to attempt to make it writeable." There are options to Overwrite, Save As... or Discard.
Select Discard to undo your inadvertent changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With