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.
Another good option is The Read-Only Indicator extension ( marketplace , github ).
You could install the Local History extension, and see if you made changes and revert them.
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.
I expect that what you need/want is: https://github.com/microsoft/vscode/issues/161715 which allows to mark files/editors as read-only when you open them, independent of the filesystem/chmod attributes. (and shows the 'lock' icon when you open a read-only file)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.