Incremental Diff
Version:
Added in:3.2
Sublime Text includes a built-in diff functionality that tracks changes to files being edited. The diff calculation is incremental, tracking each buffer modification as it is performed. It does not require the file be stored in a version control system, such as Git.
The exact location of each addition, modification and deletion is tracked. This is used to display markers in the gutter, allow navigation between each change, display inline diffs and allow for reverting changes.
Diffs are calculated against the version of the file on disk, but Diff Markers can be configured to diff against HEAD, and the API allows files to be diffed against any content.
Diff Markersπ
The following is an example of diff markers displayed when using the Mariana color scheme:
See the Color Schemes: Global Settings for information on customizing the colors and width of the diff markers.
Inline Diffsπ
In addition to tracking which lines have been modified, the incremental diff also tracks the exact changes. This allows displaying the original version of the text.
Togglingπ
When right-clicking on a modified region of a file, a menu entry Show Diff Hunk will be available. This menu item will display the previous content inline beneath the current content. Right-clicking again will show a menu item Hide Diff Hunk to hide the inline diff.
Toggling an inline diff may be performed via the Edit βΆ Text βΆ Toggle Hunk Diff menu.
In addition to menu-based activation, diffs may also be toggled via keyboard shortcut:
Windows/Linux: Ctrl+K, Ctrl+/
Mac: β+K, β+/
To toggle the diff for a region, while hiding all other diffs, press:
Windows/Linux: Ctrl+K, Ctrl+;
Mac: β+K, β+;
Stylingπ
The styles used for displaying inline diffs are automatically generated for color schemes that have not created their own rules. For custom styles, add rules with the following selectors:
diff.deleteddiff.deleted.chardiff.inserteddiff.inserted.char
Generally each rule will set the background and foreground_adjust
properties.
Revertingπ
A modification may be reverted to the original text by the keyboard shortcut:
Windows/Linux: Ctrl+K, Ctrl+Z
Mac: β+K, β+Z
Alternatively, the menu Edit βΆ Text βΆ Revert Modification may be used.
Settingsπ
- "mini_diff" boolean, stringπ
If the incremental diff functionality should be enabled. Valid values include:
trueβ always enable incremental diff"auto"β enable incremental diff for files in a Git repositoryfalseβ disable incremental diff
Default:
true
- "git_diff_target" stringπ
Controls the behavior of incremental diff for files in a Git repository. Valid values include:
"index": β diff against the Git index"head": β diff against the file at HEAD
Default:
"index"