Incremental Diff Version:
Added in:3.2
Sublime Text includes a built-in diff functionality that tracks changes to filesbeing edited. The diff calculation is incremental, tracking each buffermodification as it is performed. It does not require the file be stored in aversion control system, such as Git.
The exact location of each addition, modification and deletion is tracked. Thisis 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, butDiff Markers can be configured to diff against HEAD, and theAPI allows files to be diffed against any content.
Diff Markers🔗
The following is an example of diff markers displayed when using the Marianacolor scheme:
| 27 | ||
| 28 | A line that was added | |
| 29 | ||
| 30 | A modified line | |
| 31 | followed by another modified line | |
| 32 | ||
| 33 | The line before this was deleted | |
| 34 |
See theColor Schemes: Global Settings forinformation on customizing the colors and width of the diff markers.
Navigation🔗
Users can jump to the next or previous modification using the following methods:
Ctrl+.
Ctrl+,
Goto
Next Modification
Goto
Previous Modification
The keyboard shortcuts tend to be a very natural way to jump around a filebeing edited.
Inline Diffs🔗
In addition to tracking which lines have been modified, the incremental diffalso tracks the exact changes. This allows displaying the original version ofthe text.
Toggling🔗
When right-clicking on a modified region of a file, a menu entryShowDiff Hunk will be available. This menu item will display the previous contentinline beneath the current content. Right-clicking again will show a menuitemHide Diff Hunk to hide the inline diff.
Toggling an inline diff may be performed via theEdit Text
ToggleHunk Diff menu.
In addition to menu-based activation, diffs may also be toggled via keyboardshortcut:
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 forcolor schemes that have not created their own rules. For custom styles, addrules with the following selectors:
diff.deleteddiff.deleted.chardiff.inserteddiff.inserted.char
Generally each rule will set thebackground andforeground_adjustproperties.
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 menuEdit Text
Revert Modification may be used.
Settings🔗
- "mini_diff"boolean,string🔗
If the incremental diff functionality should be enabled. Valid valuesinclude:
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"