Vim reads your vimrc once, at startup. The if &diff
statement is executed when it is read, not every time the state of 'diff'
changes. One way to have those color commands executed when you execute :VCSVimDiff
is to put them in an autocommand in your vimrc, like this.
au FilterWritePre * if &diff | set t_Co=256 | set bg=dark | colorscheme peaksea | endif
where the FilterWritePre
event is one that is triggered when Vim performs a diff.
[The comment didn't work well, so I'll add to my original answer.]
If you want to end VimDiff with :q
, what you could do is set up another autocommand, maybe using the BufWinLeave
event, again testing &diff
and executing the commands to set your default colorscheme.
What I do is use the following command to delete the buffer I had diff'd against, turn off diff mode and restore some saved settings.
command! -bar -bang Nodiff wincmd l <bar> only<bang> <bar> set nodiff noscrollbind scrollopt-=hor wrap foldcolumn=0 virtualedit= foldlevel=99 <bar> if exists("b:fdm") <bar> let &fdm = b:fdm <bar> endif <bar> if exists("b:syn") <bar> let &syn = b:syn <bar> endif
To make and/or save those settings when diff mode is entered, I use the following autocommands.
au FilterWritePre * if &diff | set virtualedit=all | endif
au FilterWritePre * exe 'let b:syn = &syn | if &diff | set syn=OFF | endif'
au BufWinEnter * if &fdm != "diff" | let b:fdm = &fdm | endif
Those commands have evolved over the years, which is my excuse for their inconsistencies.
Note, that Vim 7.4 restores your settings when turning off diff mode. – Christian Brabandt – 2014-10-16T08:38:54.393
Interesting. Indeed, it works. Do you know a solution to "come back" to the original colorscheme when I end VimDiff with :q? – Somebody still uses you MS-DOS – 2010-06-28T17:07:30.733
If you want to end VimDiff with :q, what you could do is set up another autocommand, maybe using the BufWinLeave event, again testing diff& and executing the commands to set your default colorscheme.
What I do is use the following command to delete the buffer I had diff'd against, turn off diff mode and restore some saved settings.
command! -bar -bang Nodiff wincmd l <bar> only<bang> <bar> set nodiff noscrollbind scrollopt-=hor wrap foldcolumn=0 virtualedit= foldlevel=99 <bar> if exists("b:fdm") <bar> let &fdm = b:fdm <bar> endif <bar> if exists("b:syn") <bar> let &syn = b:syn <bar> endif – garyjohn – 2010-06-28T17:40:13.227
I moved the contents of the above comment to the answer. – garyjohn – 2010-06-28T17:57:14.763