我一直在阅读一些dotfiles(.vimrc .gvimrc)来学习一些巧妙的技巧,我遇到过这个:
if has("gui_running")
set fuoptions=maxvert,maxhorz
au GUIEnter * set fullscreen
endif
Run Code Online (Sandbox Code Playgroud)
如果这已经是.gvimrc(仅在加载gVim时加载)为什么它有条件if has("gui_running")
?这不是多余的吗?是否存在特殊问题/原因?
我知道if has("gui_running")
在脚本中使用它很有意思,我特别要求它在.gvimrc中的用途,因为它只是在我使用gvim时才获得,因此理论上并不需要.
P S*_*ved 14
保留一个配置文件而不是两个配置文件更容易(特别是如果您在多台计算机上工作,并且需要保持其配置同步).因此,而不是创造.gvimrc
和 .vimrc
,有些人可能更愿意把它所有进入.vimrc
的文件和使用警卫.
然后有人在互联网上共享这个文件,并且人们将GUI重新复制的部分复制到.gvimrc
.这就是它最终的结果.
从vim-documentation,基本上它允许你根据正在运行的gui进行各种设置.
- To check in a Vim script if the GUI is being used, you can use something
like this:
if has("gui_running")
echo "yes, we have a GUI"
else
echo "Boring old console"
endif
*setting-guifont*
- When you use the same vimrc file on various systems, you can use something
like this to set options specifically for each type of GUI:
if has("gui_running")
if has("gui_gtk2")
:set guifont=Luxi\ Mono\ 12
elseif has("x11")
" Also for GTK 1
:set guifont=*-lucidatypewriter-medium-r-normal-*-*-180-*-*-m-*-*
elseif has("gui_win32")
:set guifont=Luxi_Mono:h12:cANSI
endif
endif
Run Code Online (Sandbox Code Playgroud)
更新:
*gui-init* *gvimrc* *.gvimrc* *_gvimrc* *$MYGVIMRC*
The gvimrc file is where GUI-specific startup commands should be placed. It
is always sourced after the |vimrc| file. If you have one then the $MYGVIMRC
environment variable has its name.
Run Code Online (Sandbox Code Playgroud)