Sometimes I want to view a file without editing, but want to use some features of vi (or vim). Of course I can just use
$ vi file.txt
but then I can accidentally change the file.
There are two parameters, which can help.
The first is -R (Read only):
$ vi -R file.txt
With this parameter it is not possible to write a changed file. If you try, you will get the message
E45: 'readonly' option is set (add ! to override)
On most Linuxes there is the command view, which does the same:
$ view file.txt
An even more restrictive possibility is the parameter -M (not Modifiable).
$ vi -M file.txt
Using this parameter it is not possible to enter the edit mode – you will get the message
E21: Cannot make changes, 'modifiable' is off
This way you can be sure to keep the file intact, but you can use all the power of the other vi commands.