Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM open file in vertical split in read only mode

Tags:

vim

In vim I can open a file in a vertical split by using the command vs myfile.txt and I can open a file in a new editor, in read only mode with vim -R myfile.txt.

I want to combine these to commands, ideally vs -R myfile.txt, but of course I've already discovered that doesn't work. I want to open the file this way because I have the file open in a different tab and I want to be sure that I don't accidently edit the file.

like image 356
Gio Avatar asked Mar 24 '15 10:03

Gio


People also ask

How do I split screen vertically in Vim?

Splitting Vim Screen Vertically Press the keyboard combination Ctrl + w , followed by the letter 'v' .

How do I open a Vim file in read only mode?

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

How do I open another window in Vim?

To open a new VIM window next to the existing one, press <Ctrl>+<w> then press <v>. You can move to the left window again by pressing <Crtl>+<w> and then pressing <h>. To open a new VIM window on the bottom of the currently selected window, press <Ctrl>+<w> then press <s>.


2 Answers

The command to view a file in "readonly mode" is :view. You can split the current window and run :view:

:vs|view file

And here is a variant:

:vert sview
like image 194
romainl Avatar answered Sep 19 '22 16:09

romainl


If you want one file to be editable and only one read-only.Then

vim writablefile.txt
:vs | view readonlyfile.txt
like image 38
karthik Avatar answered Sep 17 '22 16:09

karthik