Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using the VCSCommand plugin.

I'm calling VimDiff utility inside Vim by calling :VCSVimDiff.

I have in my vimrc:

if &diff
    set t_Co=256
    set background=dark
    colorscheme peaksea
else
    colorscheme molokai
endif

It works when I call vimdiff from my console, but not when I call it from Vim using VCS.

Is this a plugin problem, or a vimrc config that is missing?

share|improve this question

3 Answers 3

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.

share|improve this answer
    
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 Jun 28 '10 at 17:07
    
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 Jun 28 '10 at 17:40
    
I moved the contents of the above comment to the answer. –  garyjohn Jun 28 '10 at 17:57

Unfortunately Vim doesn't have explicit diff mode events. You can hack around that to some extent with the suggestions from the other answers.

As an alternative to that approach, you can create a function that wraps diffthis and diffoff and change your settings in that function.

nnoremap <leader>df :call ToggleDiff()<CR>

function! ToggleDiff()
    if &diff
        diffoff
        setlocal syntax=on
    else
        diffthis
        setlocal syntax=off
    endif
endfunction
share|improve this answer
up vote 0 down vote accepted

garyjohn, thanks for your time, but I find my solution. It works!

au FilterWritePost * if &diff | set t_Co=256 | set bg=dark | colorscheme peaksea | else | colorscheme molokai | endif
au BufWinLeave * colorscheme molokai

Source

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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