Skip to content

VS Code — Read Only Files

VS Code read only files

Many applications include generated files under folders such as vendor, node_modules or OpenAPI data models or schemas.

You should not edit those files manually.

But does everyone know they shouldn’t edit those files manually?

Sadly, no.

Does something prevent you from changing the files manually?

Also, no.

That’s why in this post, we’re going to find out how to solve this problem at the editor level.

Let’s get started!

Make vendor and node_modules files read only

Press down CTRL + , (comma) to open the Settings and search for Files: Readonly Include.

Click the Add Pattern button and add the following patterns:


VS Code read only files setting

💡Good to know

Double asterisk (**) or double wildcard means that it recursively matches zero or more directories that fall under the current directory. In our case, that means all the files under the vendor and node_modules.

In addition to the fact that you can’t edit those files, you also can’t delete them, or add other files, or other folders.

VS Code read only file lock icon cannot edit file message

Now you can go into one of the files and try to modify it.

When you open the file, you’ll notice on the left side of the editor an icon with a padlock, and when you try to write something, a message will appear informing you that you can’t edit that file.

That’s it!

Happy coding 🎉

Let me know what you think about this article in the comments section below.

If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.