Open a file in a tab in vim in readonly mode

后端 未结 7 1403
刺人心
刺人心 2021-01-30 12:25

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 )

相关标签:
7条回答
  • 2021-01-30 12:47

    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.

    0 讨论(0)
  • 2021-01-30 12:53

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

    :view /path/to/file
    

    or from command line:

    $ vim -M /path/to/file
    
    0 讨论(0)
  • 2021-01-30 12:54

    vim -M filename opens the file in readonly mode.

    0 讨论(0)
  • 2021-01-30 12:55

    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.

    0 讨论(0)
  • 2021-01-30 13:00

    Something that works for me:

    :vnew path/to/file
    

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

    :view
    
    0 讨论(0)
  • 2021-01-30 13:07

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

    0 讨论(0)
提交回复
热议问题