I'm trying to configure Vim so that I can

1.  choose which filetypes have syntax coloring enabled and

2.  set syntax off when diffing files.

Without the latter, some syntax foreground colors and diff
background colors are such that the text is impossible to read.

I've discovered when diffing two files like this,

    $ vimdiff foo.xml bar.xml

that the value of the 'diff' option, &diff, is true when the
~/.vimrc is read, false when filetype pluging for the first file,
foo.xml, is read, and true again when the filetype plugin for the
second file, bar.xml, is read.  That makes it difficult to determine
in the filetype plugin whether syntax coloring should be on or off.

I think this is a bug.

The filetype doesn't matter.  XML was a convenient example.


Here is a demonstration of this behavior.  I created two special
files, ~/.vim/after/ftplugin/xml.vim:

    let diffdict[expand("%s")] = &diff
    if !&diff
        setlocal syntax=ON
    endif

and ~/testvimrc:

    set nocompatible
    set noloadplugins
    let diffdict = {}
    let diffdict["vimrc"] = &diff
    filetype plugin on
    syntax manual

and I copied two arbitrary XML files to my home directory and named
them foo.xml and bar.xml.  Then I diffed the two files and examined
the diffdict dictionary.

    $ vimdiff -u testvimrc foo.xml bar.xml
    :echo diffdict
    {'bar.xml': 0, 'foo.xml': 1, 'vimrc': 1}

Note that &diff was 0 when bar.xml was being read.  Consistent with
those results, the buffer on the left, containing foo.xml, has
syntax coloring off while the buffer on the right, containing
bar.xml, has syntax coloring on.


I've worked around the problem so far by using the following test in
my filetype plugins,

    if !&diff && (v:progname !~ "diff")
        setlocal syntax=ON
    endif

and I may do something like this in my ~/.vimrs,

    let g:diff = &diff

with a test of g:diff in my filetype plugins so that "vim -d" works
as well, but it would be nice if &diff worked as it seems it should.

The behavior of &diff has like this for as long as I've been trying
to use it this way, early 7.2 if not before.  The version I used for
this test was 7.3.138, a normal version built on a Fedora 11 system.

Regards,
Gary

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to