38

There seems to be two ways to store preferences specific to gvim:

  1. Keep an .vimrc file for vim and a .gvimrc file for gvim specific additions.

  2. Keep all settings in .vimrc and wrap gvim specific settings in a feature detection conditional:

    if has('gui_running')
        " gvim specific settings here
    endif
    

Given the existence of the latter option, why would I ever need a .gvimrc file?

  • One specific example which I find useful is winpos which changes the position of the window used by gvim. This has no effect (and makes no sense) within ~/.vimrc, it has to be in ~/.gvimrc – jalanb Feb 6 '15 at 0:02
28

When the GUI starts, some settings are reset and then .gvimrc is processed.

Consequently, if you want a non-default value for any of those settings, you'll need to set it in a .gvimrc; testing for GUI mode in .vimrc won't work.

One such setting is t_vb, the terminal code used for the visual bell; in fact, all terminal optionals are reset to defaults for GUI mode (see :help terminal-options).

Additionally a bunch of GUI setup and menu customization is carried out; if you want to tweak any of that, you'll want that in a .gvimrc or it may not have any impact.

Reading over :help gvimrc provides a good overview of things that may change on you between the sourcing of your .vimrc and .gvimrc that you may want to consider re-adjusting in the latter.

  • 3
    IIRC you can use the :gui command (within has("gui_running"), of course) to force the gui startup sequence to happen before any subsequent .vimrc commands. My .vimrc uses this to allow the default background light/dark setting to be set based on the actual GUI background color. – Random832 Feb 27 '15 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.