I have a function definition in my .vimrc. This .vimrc is sufficient to demonstrate the problem I'm asking about:
function! Greet()
echo "hello"
endfunction
I want to be able use the same .vimrc with a version of vim configured with
--with-features=tiny
I don't expect the function to be defined, but I don't want error messages on startup.
Currently, if I run a tiny vim, I get:
Error detected while processing /home/kst/.vimrc:
line 1:
E319: Sorry, the command is not available in this version: function! Greet()
line 2:
E319: Sorry, the command is not available in this version: echo "hello"
line 3:
E319: Sorry, the command is not available in this version: endfunction
Press ENTER or type command to continue
I'm looking for something like:
if has("function")
function! Greet()
echo "hello"
endfunction
endif
but that doesn't do the job because has() doesn't recognize "function". (The result is that the function definition is disabled even for versions of vim that support functions.)
I didn't see anything obvious in the documentation for has(), and web searches with the word "function" give me a lot of irrelevant hits.
:if 1tiny vim will not read anything in between this. – Christian Brabandt Jan 07 '20 at 07:25:ifas a whole or just (complex) expressions... Why does thesilent! while 0work then? Is it because it'swhileand notifso vim-tiny doesn't ignore it? Why thesilent!? – filbranden Jan 07 '20 at 07:34if 1is the documented way how to make vim.tiny skip eval code (don't ask me where this is documented, don't find it currently) and this is also what defaults.vim used initially. The thing whysilent! while 0was needed, was because we wanted to run a piece of code only in tiny vim, but not a vim that hasevalfeature. So eval vims would skip that, while tiny vim does read it. Since tiny vim do not understandwhile, we needed:silent!to not show any error message. – Christian Brabandt Jan 07 '20 at 07:49:h no-eval-feature– Christian Brabandt Jan 07 '20 at 07:58if has('eval')andif 1work. I think the former works just because the expression is ignored. I'll useif 1. – Keith Thompson Jan 07 '20 at 18:37:h no-eval-feature!) Most likely later this evening or tomorrow. Thanks again for the great discussion! – filbranden Jan 07 '20 at 18:51:help no-eval-feature, thanks @ChristianBrabandt for mentioning it! – filbranden Jan 08 '20 at 00:31