Open a file in a tab in vim in readonly mode
Solution 1
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.
Solution 2
You can open a file in readonly mode from inside vim
:
:view /path/to/file
or from command line:
$ vim -M /path/to/file
Solution 3
vim -M filename
opens the file in readonly mode.
Solution 4
Just open your file by using :tabe <filename>
, then enter :view
. It will automatically switch to read-only mode.
Solution 5
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.
Related videos on Youtube
Srikanth
Updated on July 05, 2022Comments
-
Srikanth almost 2 years
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.
-
Dharmit almost 12 years
vim -R
works as read-only mode.vim -M
opens the file with modifiable set to off.
-
-
Anthony DiSanti almost 12 yearsFor anyone that isn't looking to use tabs, simply
:view /path/to/file
will open a new buffer with the file in read-only mode -
Saulo Silva over 10 yearsHe specifically said "how to open a file from inside vim".
-
user456584 over 10 yearsStill useful for people coming in from Google.
-
Seng Cheong over 9 years@user456584 Only for those who are bad at using Google. This question is specifically about opening read-only in a tab.
-
Seng Cheong over 9 yearsThis question is specifically about opening read-only in a tab.
-
Aman about 8 yearsI like this alternative; fits my normal workflow for tabs, and easier to remember.
-
erikbstack over 7 yearsIt's still good you posted that, because I came here exactly for that!
-
jpaugh over 7 yearsuser2015258's answer does this in one step.
-
shaahiin over 5 yearsYou can use
vim -R filename
for opening the file in read-only mode (file is modifiable, but not writable) andvim -M filename
for opening the file with modifiable set to off (file is neither modifiable, nor writable).