Linux – How to open a file read-only from command line with emacs/vi/vim

command lineemacslinuxvim

Is there a way to tell emacs/vi/vim (from the command line) that I want to view the file in view-mode or read-only.

I know how to open a file as read only if emacs/vi/vim is already running.

Best Answer

For emacs:

emacs FILE --eval '(setq buffer-read-only t)'

There's no startup option to force read only.

If you put this small function in your shell startup script (.bashrc for example) you can open a file read-only by typing ev file_to_view

ev() {
  emacs "$1" --eval '(setq buffer-read-only t)'
Related Question