Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why some people use 'if has("gui_running")' in a .gvimrc?

Tags:

vim

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.

like image 460
Somebody still uses you MS-DOS Avatar asked Nov 19 '10 21:11

Somebody still uses you MS-DOS


People also ask

Does Gvim use Vimrc?

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 ~/.

What is Gvimrc?

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.


2 Answers

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.

like image 142
nelstrom Avatar answered Sep 25 '22 11:09

nelstrom


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.

like image 28
P Shved Avatar answered Sep 23 '22 11:09

P Shved