简体   繁体   中英

Why my function in .vimrc got called automatically?

As I know, we could define function in .vimrc as below:

function Fun()
    do something here
endfunction

Then we could call it like :call Fun() .

For one of my system, there's only the function definition in my .vimrc, however the function is always exectued once I get into vim. Why?

Below is version of my 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 

And my .vimrc:

# cat ~/.vimrc
function Fun1()
        :!ls
endfunction

Function name doesn't matter, I've changed the name as a test.

Update on July 8, 2015:

According to the answer from Ben, and since I'd like my .vimrc be compatible over multiple environments, I wrap the function definition with if has('eval')...endif as my finial solution:

if has('eval')
    function! Fun1()
        do something
    endfunction
endif

Your vim is compiled without "eval" support. That means your Vim does not support defining functions. The opening function Fun1() command is therefore invalid, and ignored. Then the function definition is executed because those are valid commands.

You will need to install a more fully-featured Vim, or compile your own Vim, or find an alternate Vim installation on your system that has more features. "eval" comes with a NORMAL or larger feature set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM