Srikanth
Srikanth

Reputation: 12110

Open a file in a tab in vim in readonly mode

I'm aware of opening files in readonly mode from shell using vim -R, but how to open a file from inside vim in a separate tab (:tabe <filename>) in readonly mode?

Thanks for your time.

Upvotes: 95

Views: 54033

Answers (7)

ghchoi
ghchoi

Reputation: 5156

vim -R /path/to/file
vim -m /path/to/file

Read-only mode. Modification in text is allowed but you cannot write (no saving).

vim -M /path/to/file

Even modification in text is not allowed.

Upvotes: 8

ZyX
ZyX

Reputation: 53624

To open a file in read only mode in a new tab, use

tab sview /path/to/file

To open the file in the same pane, (without using a new window or tab), use

view /path/to/file

Note that tab view /path/to/file does not open a new tab.

Upvotes: 94

Mr Lou
Mr Lou

Reputation: 1807

vim -M filename opens the file in readonly mode.

Upvotes: 32

Vivek
Vivek

Reputation: 106

Something that works for me:

:vnew path/to/file

and once the file is opened, give the view command:

:view

Upvotes: 2

user2015258
user2015258

Reputation: 1357

You can open a file in readonly mode from inside vim:

:view /path/to/file

or from command line:

$ vim -M /path/to/file

Upvotes: 46

Jeyamaran
Jeyamaran

Reputation: 783

Just open your file by using :tabe <filename>, then enter :view. It will automatically switch to read-only mode.

Upvotes: 23

Wyatt Anderson
Wyatt Anderson

Reputation: 9893

Try :tabedit +set\ noma|set\ ro FILE; this will open FILE in a new tab with modifiable off and readonly on, preventing you from modifying or writing the file. If you just want readonly, omit the noma set. Might be convenient to remap this to another command.

Upvotes: 5

Related Questions