Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why my function in .vimrc got called automatically?

Tags:

function

vim

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 <[email protected]>
Compiled by <[email protected]>
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
like image 879
Qiu Yangfan Avatar asked Feb 03 '26 17:02

Qiu Yangfan


1 Answers

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.

like image 111
Ben Avatar answered Feb 05 '26 07:02

Ben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!