目录

判断当前是VIM还是GVIM模式

方法一

If Vim is running in GUI mode, or if it is in startup and knows that GUI mode will be started at the end of startup, has('gui_running') returns 1 (i.e. TRUE). Otherwise it returns 0 (i.e. FALSE). You can test this (unless running on a Vim without arithmetic evaluation) with

       if has('gui_running')
               " gvim-only stuff
       else
               " non-gvim stuff
       endif

或者

       if !has('gui_running')
               " this won't be done when staying in console mode
       endif

参考

方法二

Whenever the GUI is started (be it during startup, or, on a Unix Vim, by executing the :gui command at any time), your gvimrc is sourced and (provided, of course, that autocommands are compiled-in) the GUIEnter autocommand event is triggered. Neither happens if Vim runs in console mode.

参考