Robert Hicks wrote:
A.J.Mechelynck wrote:
Robert Hicks wrote:
[...]
I only use a .vimrc and for the things that are gui specific I wrap in:

if has("gui_running")
    " stuff for gvim
endif

Is there any reason NOT to do that if I only want to maintain one config file?

Robert



I do that too. For the settings which must wait until the GUI starts (like setting t_vb again) I use instead something like

    if has("gui")
        autocommand GUIEnter * set t_vb=
    endif

which, however, does rely on +autocmd being compiled-in. This is not really a problem for me, since in the rare cases when I use a "tiny" version of Vim, it is not GUI-enabled.

With Unix versions of gvim, it is possible to start a GUI-enabled Vim in console mode, do some editing (so has("gui_running") is off while sourcing the vimrc) and later change one's mind and use the :gui command to start the GUI. In practice I don't do that, however, so (in practice) when has("gui_running") is false, I'm not going to go from console mode to GUI mode in the course of the current session.

I think that what it comes to in the end is a question of personal preference.


Er so it is safer to use:

if has("gui")

I didn't know you could do that with Vim myself. If I am on the console I use vim and if I want the gui version I type gvim.

Robert



has("gui") means "GUI capabilities are compiled-in". has("gui_running") means "We are running in GUI mode now (or about to start it)". An autocommand for the GUIEnter event will only be triggered if and when the GUI starts; I wrap it in has("gui") to avoid syntax errors. That way, it will still be triggered if Vim (with GUI enabled) is started in console mode and later changed into a GUI by issuing ":gui" explicitly. Other settings, which are set in the vimrc and "remembered" automatically, like

        set guifont=...
        set lines=...
        set columns=...
        winpos...

should be wrapped in «if has("gui_running")» because we don't want to execute them if we're running in console mode, not even on a GUI-enabled Vim for Unix. This, however, assumes that we aren't guing to use ":gui" after having run in console mode for some time (which is not possible on Windows anyway). If we want to be able to do that, then it's probably better to move gvim settings to a gvimrc file.

In short:
- On Windows, console Vim and gvim are necessarily two different executables; so has("gui") and has("gui_running") are always synonymous. - On Unix/Linux, a single executable can run in console mode (when invoked as "vim" "view" etc.) or in GUI mode (when invoked as "gvim" "gview" etc. or with the -g command-line switch). has("gui_running") can be FALSE even if has("gui") is TRUE. In some cases it makes a difference which one was used.


Best regards,
Tony.

Reply via email to