I typically use set cursorline by default and it works reasonably well with my preferred color schemes (molokai, vividchalk, moonfly). In normal mode. In diff mode, it almost always screws things up. In particular comment lines are almost always unreadable when highlighted by both the diff colors and the cursor line.

Is it possible to setup my config so that set nocursorline gets run any time I enter diff mode (whether starting with nvim -d or using vim-fugitive to run :Gdiff or manually starting :diffthis) and then have it turn back on when going into normal highlighting mode?

P.S. It might matter that I'm running Neovim because I believe the startup order is different and setting GUI properties is available at a different point in the configuration process. However I'm hopping for something that works at both startup and when entering diff mode in an already running editor.

1 Answer 1


One would expect, that the OptionSet autocommand is triggered when entering diff mode. Unfortunately that is currently not the case. So I created a patch that will enable this behavior. Once it is merged, you can basically do this:

au OptionSet diff let &cul=!v:option_new

As a workaround, currently you have to do something like this:

augroup MyCursorLine
  au FilterWritePost * if &diff | let &cul=0 |endif
  au BufEnter * if !&diff | let &cul=1 |endif
augroup end
  • Thanks! The trust the patch will be awesome (and it looks like nvim will need a similar fix). Your work around solution works great for some cases, but not all. It works in the context of opening a pane as a split (as happens with :Gdiff) and works one direction for entering diff mode via vim -d or setting :diffthis on two existing panes, but for these last two instantiations in doesn't work the other way ... the cursorline doesn't come back when running :diffoff or closing the extra panes. This is not a big deal for me as 95% of the annoyance is relieved, just pointing it out...
    – Caleb
    Jul 10, 2017 at 8:26
  • the patch has been included as of 8.0.0736 Jul 20, 2017 at 6:12
  • 1
    @ChristianBrabandt The autocommand is not called when closing the diff window and I cannot attain the toggling behavior. This is my autocmd: autocmd OptionSet diff ALEToggleBuffer. The ALEToggleBuffer is called when I am entering the diff mode by Gdiff. But when I exit the diff mode by closing one window, the autocommand is not getting triggered but the set diff? return nodiff for the window. Can you help? Mar 5, 2019 at 9:11
  • Ironically I found this post recently searching the internet for how to turn off the option. Apparently (perhaps a side effect of this being patched in both vim and nvim) this hack has the unfortunate effect of not being able to even disable cul when not in diff mode. You can turn it off for one buffer for a moment, but it inevitably turns itself on again.
    – Caleb
    Mar 7, 2019 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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