In my .vimrc, I'd like to be able to check if I've been run either by vim -R or view. If so, I plan to either disable or delay some plugins from loading to speed up the times when I quickly want to look at a file.
:args and argv() only seem to show me which files I wanted to edit, not all the command line flags.
Checking if &readonly almost works. If I have this:
if &readonly
echo "read only"
else
echo "not read only"
endif
Then I get read only echoed when I execute view or vim -R, but if I do either view ~/.vimrc or vim -R ~/.vimrc then I get not read only. Very strange.
Thanks!
We can now exit normally by typing ESC :q! since the file is still opened as read-only.
Press the [Esc] key and type Shift + Z Z to save and exit or type Shift+ Z Q to exit without saving the changes made to the file.
vi -R filename Opens an existing file in the read-only mode.
Vim's program name (eg view) can be detected with the v:progname variable. This doesn't solve checking for vim -R, but it does allow you to use this variable in a condition in your .vimrc and potentially improve the efficiency of your config. For example:
if v:progname ==? 'view'
" Do something
endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With