收录日期:2019/12/07 11:54:11 时间:2010-10-28 14:19:08 标签:vim,tabs,readonly

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.

tab sview /path/to/file

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

:view /path/to/file

or from command line:

$ vim -M /path/to/file

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

vim -M filename open the file in readonly mode

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.