vimtricks.wiki Concise Vim tricks, one at a time.

How do I turn off diff mode in all windows at once after comparing files?

Answer

:diffoff!

Explanation

The :diffoff! command exits diff mode in every window simultaneously. Without the !, :diffoff only deactivates diff mode in the current window, leaving other windows still highlighting differences. The ! bang variant clears the diff state globally across the entire tab page.

How it works

  • :diffoff — turn off diff mode for the current window only
  • :diffoff! — turn off diff mode for all windows in the current tab

The command also unsets 'diff', 'scrollbind', 'cursorbind', and 'scrollopt' in each affected window, fully restoring them to their pre-diff state.

Example

A typical vimdiff session:

" Open two files side by side in diff mode
:windo diffthis

" ... review the differences ...

" Exit diff mode in all windows cleanly
:diffoff!

Without :diffoff!, you would need to manually run :diffoff in each window after navigating to it with <C-w>w.

Tips

  • Pair with :diffupdate to refresh the diff if the buffer content changed without triggering a rediff
  • Use :windo diffthis to quickly enter diff mode for all currently open windows
  • If you opened files with vimdiff from the shell, :diffoff! is the cleanest way to return all windows to normal mode

Next

How do I configure Vim's command-line tab completion to show all matches and complete to the longest common prefix?