Reputation: 31
view
command do open a file in ready only mode.
However, I found that in my mac, view
command is actually the soft link to vim:
ll /usr/bin/view
output:
lrwxr-xr-x 1 root wheel 3B Nov 19 14:25 /usr/bin/view -> vim
So I wonder: when I open a file with this command:/usr/bin/view /path/to/file
. how does vim automaticlly turn on read only mode as I have not set any specific param?
Upvotes: 0
Views: 51
Reputation: 3671
Commands can look up the name by which they were invoked (using, for example, argv[0]
in C) and change their behaviour accordingly. So in this case vim
knows that if is is run as view
, it should behave as if the read-only -R
flag has been set.
From the vim
man page:
Vim behaves differently, depending on the name of the command (the exe‐
cutable may still be the same file).
vim The "normal" way, everything is default.
view Start in read-only mode. You will be protected from writing
the files. Can also be done with the "-R" argument.
Upvotes: 2