Straightforward question here and I can't make it any simpler than the title:
How do I set VIM to open files in "read-only" mode by default?
Thanks!
You can press Esc , and then U , and then type :q . First come out of the vim editor using: :qa!
Just use vi's exclamation mark suffix to the write command (:w!) to force overwriting your own READONLY file.
vi -R filename Opens an existing file in the read-only mode.
Protects you from accidentally overwriting a file. Default on when Vim is started in read-only mode ("vim -R") or when the executable is called "view". When using ":w!" the 'readonly' option is reset for the current buffer, unless the 'Z' flag is in 'cpoptions'.
add
set ro
to your .vimrc
.
Also: commonly, you can type view filename
instead of vim filename
and it will open vim in readonly mode.
vim -R filename
will open file in read-only mode.
this still will allow you to modify buffers, if you want to prohibit this - there's an option :set nomodifiable
, to allow modification use :set modifiable
.
There's short version for those who in hurry,:set ma
and :set noma
does the opposite.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With