开发者

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

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 f开发者_开发知识库ullscreen
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.


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.


From vim-documentation, basically it allows you to do various settings depending on which gui that is running.

- 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

UPDATE:

            *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.


Could it be the case .gvimrc is read if you call start the program by using gvim instead of vim? The only difference that I can see is if you are calling gvim in a setting where it cannot start (example, you are in ssh session without X). In that vim is going to be run, but the file might still be sourced.

(I don't really know if this is the case, in my system I have compiled vim without X, so I cannot test it)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜