13

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.

Gio
  • 3,242
  • 1
  • 25
  • 53
  • 2
    This may answer your question: http://stackoverflow.com/questions/4043650/open-a-file-in-a-tab-in-vim-in-readonly-mode – Jan Spurny Mar 24 '15 at 10:26

2 Answers2

18

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
romainl
  • 186,200
  • 21
  • 280
  • 313
  • Ok. so it does work, you just need to split `vs` and then type `view`. The oneliner `vs|view file` however doesn't work for me. – Gio Mar 24 '15 at 10:53
  • Sorry, indeed it does work. I was mistaken because it didn't show readonly in th footer. – Gio Mar 24 '15 at 11:00
  • 1
    See `:help 'statusline'` for adding the "readonly" indicator in your statusline. – romainl Mar 24 '15 at 11:07
2

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

vim writablefile.txt
:vs | view readonlyfile.txt
karthik
  • 7,041
  • 1
  • 13
  • 12