You can open a file in read-only mode in Vim using the -R
or --readonly
option, either when starting Vim or from within the editor.
Here are two ways to do this:
- When starting Vim:
vim -R <file>
- From within the editor:
Start Vim as you normally would, then enter the following command:
:set ro
This will change the file to read-only mode, and you won’t be able to make any changes to the file. To exit the read-only mode, enter the following command:
:set noro