How can I open a file read-only from command line with emacs/vi/vim
vim -R filename
For emacs:
emacs FILE --eval '(setq buffer-read-only t)'
There's no startup option to force read only.
Edit:
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)'
}
view filename
Basically vim in read-only mode; simples!
As hinted by comment, in case view
is linked to plain vi
, here are bash commands to first inspect situation and then fix it:
# non-destructive inspection
which vim
which view
ls -l $(which view)
# overwrite current view with symlink to vim, requires root
ln -sfv $(which vim) $(which view)