Today I was learning the different methods for opening a file in Vim, and I recently learned the view [filename] or [vim_launcher] -R [file_name], while both of these commands are great, they don't actually force the Read-only mode, because you can still exit that mode and enter insert mode, the only good thing about the Read-only mode is that you will get a nice-looking warning message when trying to edit the file.

When you actually open a file in Read-only, you want to avoid any type of mutation by accident, but the corresponding methods are not a good patch for this specific context.

I have done some digging but found no answer to this:

How to force the Read-only mode in the Vim | NVim text editor?

  • This question is essentially a special case of "how can I protect me from myself?" and the answer is a crushing "you cannot". Just don't change that file!
    – Friedrich
    Commented Feb 12 at 19:25

2 Answers 2


There is actually a solution for this, you can use the -m option in addition to the -R option, where m stands for no modification, which stops you from writing to the file, even if you have committed any type of editing.

So [vi_launcher] -R [file_name] becomes [vi_launcher] -mR [file_name]

I think this still can't replace the fork of the Read-only mode, there should be a better solution to this.

  • 1
    See :help 'modifiable' and :help 'readonly'
    – D. Ben Knoble
    Commented Jan 15 at 20:57

I've aliased the less.sh script that ships with vim to vless. It does what you're asking for.

alias vless='/usr/local/share/vim/vim91/macros/less.sh'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.