Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set VIM to open files in "read-only" mode by default?

Tags:

vim

readonly

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!

like image 705
daveslab Avatar asked Jul 30 '10 20:07

daveslab


People also ask

How do I override a readonly in vim?

You can press Esc , and then U , and then type :q . First come out of the vim editor using: :qa!

How do I make a file read only in vi?

Just use vi's exclamation mark suffix to the write command (:w!) to force overwriting your own READONLY file.

Which command opens an existing file in read only mode in vi editor?

vi -R filename Opens an existing file in the read-only mode.

Why is vim in read only?

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'.


2 Answers

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.

like image 101
Peter Avatar answered Oct 02 '22 06:10

Peter


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.

like image 23
holms Avatar answered Oct 02 '22 08:10

holms