Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Different use of vi or vim editor for opening in read-only mode
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Different use of vi or vim editor for opening in read-only mode

There are some situations like we need to view a file but we accidentally typed or misspelled something and saved.This is threat to file integrity an hence needs to avoided.

The solution is view files by vi or vim command by read-only mode.

view command

Simply open your file in view command and any attempt to alter or save changes will result in failure. If suppose you get into INSERT mode , you will get warning.

Using vi or vim command with -R option

The -R option is working same as the above one

--->> vi -R file name

using vi or vim command with -M option

-M = modifications are not allowed

All those three options are set for viewing a file in linux server/system in a secure way.

Comments

  • WAT

    :q! this thread!

  • raindog308raindog308 Administrator, Veteran

    I wonder how many people know about the 'view' command. I frequently use it but I never see others use it.

    Graybeard arcanery or widely known?

  • less does more than more

    (and other various things found in bsd-fortune can be posted 4 more times so I get my provider tag)

    Thanked by 1JahAGR
  • By design itself, its hard to accidentally fuck something up with vi when you clearly just want to read the file.

    Thanked by 1vedran
  • most people use vim command , because sometimes vi won't work as expect. But using view command is less. Thats a truth

  • VIM and vi aren't even the same fucking thing you idiot. A symlink to vi from VIM enables 'vi compatibility mode' for vi, which is a completely different product, but is a 'workalike'. nvi, elvis, vile, and so forth are also semi-vi-compatible editors.

    I pray to god you aren't posting this shite to get a provider tag, because you know very little.

  • @WSS said:
    VIM and vi aren't even the same fucking thing you idiot. A symlink to vi from VIM enables 'vi compatibility mode' for vi, which is a completely different product, but is a 'workalike'. nvi, elvis, vile, and so forth are also semi-vi-compatible editors.

    I pray to god you aren't posting this shite to get a provider tag, because you know very little.

    I wonder where i have said vi and vim are same , i just said using vim is easier than vi. I pray you don't hang yourself in simple matter of discussion , my friend.

  • I can't really see the point. Complex configs you should backup file with different name. Simple files just don't save after looking at them - and you can always fix the file anyway.

  • varwwwvarwww Member
    edited February 2017

    :q!

    less filename

  • raindog308raindog308 Administrator, Veteran

    WSS said: less does more than more

    varwww said: less filename

    fuck less.

    No seriously. Why should I learn a completely different set of key bindings just to read a file? more/less are fine if all you want to do is spacebar through a file.

    less doesn't let you transform the text with awk/sed/cut/etc. commands, which is a big part of using vi. I admit I don't do that often if I open a file read only but it's still handy sometimes.

    HostGliders said: most people use vim command , because sometimes vi won't work as expect.

    vim implements even vi bugs :-) If you call it as 'vi' you get exactly vi behavior, for a sort of general consensus view of what vi is, which doesn't matter much in practice.

    HostGliders said: i just said using vim is easier than vi

    I don't agree - it's vi only with more features so if anything, it can be more difficult.

    Ole_Juul said: I can't really see the point. Complex configs you should backup file with different name. Simple files just don't save after looking at them - and you can always fix the file anyway.

    Who said anything about config files? :-) You can use view for files for any purpose. But I do use it for config files if I'm just looking for something. Why open a file with more perms than you need?

    Not that any of this is a big deal, really...it's just one command.

    miau said: By design itself

    vi was not designed. It was written in a weekend. Bill Joy explained this once and admits he got lucky with how well it's worked.

    miau said: its hard to accidentally fuck something up with vi when you clearly just want to read the file.

    dG. Oops! Sure, you'd have to save but people have finger macros...

  • why not make a bash alias ?

  • bsdguybsdguy Member
    edited February 2017

    'i' is about the first vi command anyone learns. So, what's the problem in the first place? That whole situation seems to be quite contrived.

    newb: won't use vi anyway to view a file and will prefer nano for editing.

    not newb: might use vi for looking at files and if so, will certainly not occasionally hit 'i' and the type some shit and then ':w'. Most probably will use more or similar to view and nano or jed or similar to edit.

    i contrived bullshitESC:q!

Sign In or Register to comment.