Why is my function in .vimrc called automatically?

As I know we could define a function in .vimrc like below:

function Fun()
    do something here
endfunction

      

Then we could call it like :call Fun()

.

For one of my systems, there is only a function definition in my .vimrc, however the function is always called as soon as I get into vim. Why?

Below is my vim version:

# 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

      

The function name doesn't matter, I changed the name as a test.

Update as of July 8, 2015:

As per the answer from Ben, and since I want my .vimrc to be cross-environment compatible, I complete the function definition if has('eval')...endif

as my final solution:

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

      

+3


source to share


1 answer


Your vim is compiled without "eval" support. This means that your Vim does not support defining functions. Therefore, the opening command is function Fun1()

invalid and ignored. The function definition is then executed because these are valid commands.



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

+5


source







All Articles