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.
The following is an example of diff markers displayed when using the Mariana color scheme:
|28||A line that was added|
|30||A modified line|
|31||followed by another modified line|
|33||The line before this was deleted|
See the Color Schemes: Global Settings for information on customizing the colors and width of the diff markers.
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.
When right-clicking on a modified region of a file, a menu entrywill be available. This menu item will display the previous content inline beneath the current content. Right-clicking again will show a menu item to hide the inline diff.
Toggling an inline diff may be performed via themenu.
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, ⌘+;
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:
Generally each rule will set the
A modification may be reverted to the original text by the keyboard shortcut:
Windows/Linux: Ctrl+K, Ctrl+Z
Mac: ⌘+K, ⌘+Z
Alternatively, the menumay be used.
- "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 repository
false– disable incremental diff
- "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