On 28/09/09 05:10, pansz wrote:
>
> Harry Putnam 写道:
>> Do your saying it can't be done from a single .vimrc file?
> No, I'm saying you should not rely on has("gui_running").
>
>>
>> So how can I have gvim run with the settings in place, but not bother
>> my vim settings, and not have to maintain another init file?
>
> If you want to omit the .gvimrc, you should put everything you want in
> your .gvimrc in the GUIEnter autocommand. and of course, you can put the
> autocommand in your .vimrc, something like:
>
>       autocmd GUIEnter *
>           \ foobar1
>           \ foobar2
>           \ foobar3

Actually, you don't have to put _everything_ GUI-related in autocommands:

- On Windows, a single binary is either a console utility or a GUI, but 
not both, so if you're Windows-only has("gui_running") is enough [and 
equivalent to has("gui")]. Or even if you use a single vimrc on both 
Windows and Linux, has("hui_running") is criterion enough to know when 
to set which Windows-specific settings: for instance, the 'guicursor' 
setting specific to the Dos/Windows console.
- Even on Unix, if you know in advance that you won't be using the :gui 
command, has('gui_running') is good enough for you.
- Many GUI-related settings have no effect in Console Vim, except that 
it remembers them for when (and if) the GUI will be started. A few of 
these are
        'guifont'
        'guioptions'
        'guicursor' (except on Dos/Windows, see above)
There are others. You can set these in your vimrc without bracketing 
them in has('gui_running'); or (if you sometimes run non-GUI-enabled 
versions) by bracketing them in just has("gui") to prevent an error on 
versions which don't recognise the option.

There are a few settings, however, which are always reset at GUI 
startup, and these require either a gvimrc or a GUIEnter autocommand, 
even (I think) on Windows. One of these is 't_vb', as explained under 
the help for 'visualbell'. For instance, if you want both a visual and 
an audible bell, here's how to do it in all versions of Vim on most 
kinds of display (using the ASCII control character BEL):

        set errorbells visualbell
        if !has('gui_running')             " console Vim setting
                let &t_vb = "\x07" . &t_vb " also ring the bell
        endif
        if has('autocmd') && has('gui')
                " must set it again for the GUI
                au GUIEnter * let &t_vb = "\<C-G>\e|50f"
                " where 50 = flash time in milliseconds (default 20)
        endif

Similarly, (unless you'll never be using the :gui command) if you want 
to use, let's say, a _different_ colorscheme in Console Vim and in gvim, 
or _different_ 'lines' and 'columns' settings, etc., you have to set the 
GUI setting in a gvimrc or at the GUIEnter event. (There are 
colorschemes which work in both gvim and Console Vim, and not 
necessarily with the same colours; or if your console has 88 colours or 
more, you can avail yourself of the CSApprox plugin to make a 
gui-enabled Console vim use "the best approximation" to what it would 
use as a GUI).

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to