I've been reading some dotfiles (.vimrc .gvimrc) to learn some neat tricks, and I've come across this one:
if has("gui_running") set fuoptions=maxvert,maxhorz au GUIEnter * set fullscreen endif
If this is already a .gvimrc (only loaded if gVim is loaded) why does it have the condition if has("gui_running")
? Isn't this redundant? Is there an special issue/reason for that?
I know that if has("gui_running")
is interesting to use in scripts and such, I'm asking specifically for it's uses in .gvimrc, because it's only sourced when I use gvim, so in theory, is not needed.
GVIM also reads your ~/. vimrc ; most of the configuration belongs there, and only there. Only configuration exclusive to the GUI should be placed in the ~/.
File used by Gvim, a graphical version of the Vim text editor for the desktop; specifies default settings for the editor, such as the font, colors, the window size, and tab widths; similar to a . VIMRC file but can contain additional configuration options specific to Gvim.
The gvimrc file that the OP linked to was mine, so I had better own up and admit that it was done for no good reason.
I copied that snippet from Hacking without distractions, which recommends putting it in your vimrc. Then at some point I realized it would be neater to move it into the gvimrc file, but I didn't think it through clearly and left the if has('gui_running')
check in place. You're right to point out that it is unnecessary, so I have now removed it.
For the sake of posterity, here's my gvimrc before and after the change.
Keeping one config file instead of two is easier (especially if you work on several machines, and need to keep their configs in sync). So instead of creating .gvimrc
and .vimrc
, some might prefer to put it all into .vimrc
file and use guards.
And then someone shares this file in the internet, and people copy GUI-relared sections of it to .gvimrc
. That's how it ends up there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With