Posted in vim

vi: Read Only Command Line Parameters

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s