... or in any mode for that matter.
I just want to prevent some extensions from loading when that is the case, something like:
if ! currentmode('restricted')
Bundle('some-extension')
endif
If a leading r is prepended to any of the names, vim enters "restricted" mode, where certain actions are disabled. vim has a large number of command-line options. The most useful are described here: -c command. Execute command upon startup.
DESCRIPTION. Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs.
You're right; a special variable like v:vimmode
would be helpful, but I don't think such a thing currently exists. Why not raise this on the vim_dev mailing list?!
In the meantime, you have to detect the mode through the result of invoking something that is forbidden in restricted mode. My best idea that is the least intrusive on success is invoking writefile()
with an empty file name:
silent! call writefile([], '')
" In restricted mode, this fails with E145: Shell commands not allowed in rvim
" In non-restricted mode, this fails with E482: Can't create file <empty>
let isRestricted = (v:errmsg =~# '^E145:')
I am not sure if this is a good idea:
restricted-mode
disabled external commands (also some related functions). If we call external command or some certain functions in a rvim, we get Error E145
.
So maybe you could just call some dummy external command via system()
, then catch the Exception E145
. to distinguish if it is in restricted mode. e.g.
try
call system("echo x") "or even call system("")
catch /E145/
"your codes
endtry
hope it helps
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