为什么.vimrc中的函数会被自动调用?

Qiu*_*fan 3 vim function

据我所知,我们可以在.vimrc中定义函数,如下所示:

function Fun()
    do something here
endfunction
Run Code Online (Sandbox Code Playgroud)

然后我们可以这样称呼它:call Fun().

对于我的一个系统,我的.vimrc中只有函数定义,但是一旦进入vim,该函数总是被激活.为什么?

下面是我的vim的版本:

# vi --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Feb 17 2012 10:24:10)
Included patches: 1-411
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Small version without GUI.  Features included (+) or not (-):
-arabic -autocmd -balloon_eval -browse +builtin_terms -byte_offset -cindent 
-clientserver -clipboard -cmdline_compl +cmdline_hist -cmdline_info -comments 
-cryptv -cscope -cursorshape -dialog -diff -digraphs -dnd -ebcdic -emacs_tags 
-eval -ex_extra -extra_search -farsi -file_in_path -find_in_path -float 
-folding -footer +fork() -gettext -hangul_input +iconv -insert_expand +jumplist
 -keymap -langmap -libcall -linebreak -lispindent -listcmds -localmap -menu 
-mksession -modify_fname -mouse -mouse_dec -mouse_gpm -mouse_jsbterm 
-mouse_netterm -mouse_sysmouse -mouse_xterm +multi_byte -multi_lang -mzscheme 
-netbeans_intg -osfiletype -path_extra -perl -printer -profile -python 
-quickfix -reltime -rightleft -ruby -scrollbind -signs -smartindent -sniff 
-startuptime -statusline -sun_workshop -syntax -tag_binary -tag_old_static 
-tag_any_white -tcl +terminfo -termresponse -textobjects -title -toolbar 
-user_commands -vertsplit -virtualedit +visual -visualextra -viminfo -vreplace 
+wildignore -wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp 
-xterm_clipboard -xterm_save 
   system vimrc file: "/etc/virc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall  -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64  -D_FORTIFY_SOURCE=1        
Linking: gcc   -L/usr/local/lib -o vim       -lm  -lselinux -lncurses -lacl 
Run Code Online (Sandbox Code Playgroud)

而我的.vimrc:

# cat ~/.vimrc
function Fun1()
        :!ls
endfunction
Run Code Online (Sandbox Code Playgroud)

功能名称没关系,我已将名称更改为测试.

2015年7月8日更新:

根据Ben的回答,由于我希望我的.vimrc在多个环境中兼容,我将函数定义包装if has('eval')...endif为我的最终解决方案:

if has('eval')
    function! Fun1()
        do something
    endfunction
endif
Run Code Online (Sandbox Code Playgroud)

Ben*_*Ben 5

您的vim编译时没有"eval"支持.这意味着你的Vim不支持定义功能.function Fun1()因此,打开命令无效,并被忽略.然后执行函数定义,因为它们有效的命令.

您需要安装功能更全面的Vim,或者编译自己的Vim,或者在系统上找到具有更多功能的备用Vim安装."eval"附带NORMAL或更大的功能集.