37
votes

Can't seem to find anything online. Frequently spend time editing multiple text documents at the same time and loose track of which ones I have edited. When I close I am not always sure whether I have purposefully changed or accidentally edited a character in a file. Would be great to have a feature to show the edits since last save for sublime text.

Seems like such an obvious need that I am surprised that I cannot find anything in features. Am I missing something or am I the only one with this need?

5
are you just trying to find out if a document has been edited, or what exactly those edits are? - MattDMo
standard feature already show small dot, James Chevalier suggestion is great to add a visual cue for files that have been modified even if the sidebar is closed. @AaronAsAChimp gave the exactly what I have been looking for. Quickly doing a diff on what has been changed since the last save of document - Joop

5 Answers

95
votes

I know this already has an accepted answer, but it is not necessary to install FileDiffs or anything else. Just right click on the modified window and select Show Unsaved Changes.

A pane will show up at the bottom, listing the differences. There isn't an obvious way to dismiss the pane, but Ctrl+F will replace it with the search pane again.

7
votes

Add this line to your Preferences.sublime-settings file (If you're on a Mac, then open the Sublime Text 2 menu -> Preferences -> Settings - User):

"highlight_modified_tabs": true

This will highlight tabs that have unsaved changes.

6
votes

You may use the "Marking Changed Rows" plugin, which places a small gutter marker for lines with unsaved changes.

5
votes

You can install the FileDiffs plugin which among other useful things will give you a diff between the current (edited) file and what is saved to disk.

0
votes

Show Unsaved Changes

Right-clicking anywhere in the file has long provided an option to show all unsaved changes.
It will list all changes in the dialog area also used for find/replace.
This should work for Sublime Text 2 and 3.

Incremental Diff

A more recent version of Sublime Text 3 added an Incremental Diff feature.

The gutter shows which lines have changed.
This works both for unsaved changes, as well as changes between file saves or git commits.
It can be configured to show diffs against: the last saved version (git not needed), git Head, or (via the API) any other content.

Show modifications:

Right-Clicking the

  • gutter marker, or
  • any code next to the gutter marker
    (aka any area of modified code whether or not your theme shows gutter markers)

brings up options to:

  • show the diff versions inline, or to
  • open a dialog showing all tracked diffs

Or you can use the menu item:
Edit -> Text -> Toggle -> Hunk Diff
Or the shortcuts:
Ctrl + / (on Mac it's the clover icon, not Ctrl)
Or this shortcut variation, which will also close/hide all other diff Hunks
Ctrl + ; (on Mac it's the clover icon, not Ctrl)

I'm unaware of a menu item to show all unsaved changes.

Menu Items and Shortcuts are available to navigate between changes, and revert individual (inline) changes. (see linked doc above for details).

minor caveats:

  1. your theme must support diff styling to be able to see the gutter markers. The docs indicate how to add custom styles if you use an older theme that does not include the necessary styles.
    However, functionality should still work, even if you cannot see the gutter markers, as long as the option is enabled in your Preferences file.
  2. if you make an edit, then change it back, the buffer will still be tagged as having (2) changes, unless you reverted via Undo (ie Ctrl-Z). It is not a "file diff" as much as it is a tracker for the edit buffer, which stores what and where. However, the Show Diff Hunk option will show you whether the change was "important", an actual file diff, or not.

Navigate:

To navigate between modifications (whether or not your theme shows gutter markers):
Ctrl + .
Ctrl + ,
menu Goto -> Next Modification
menu Goto -> Previous Modification

Revert a Hunk:

With cursor over modified code or gutter (whether or not your theme shows gutter markers):
Ctrl + K, followed by Ctrl + Z (on Mac it's the clover icon, not Ctrl)
menu Edit -> /Text -> Revert Modification

This will only act on the diff Hunk that is at the location of your cursor.
It will not have any effect if your cursor is not in an area of modified code / diff Hunk.

Here are the Sublime Text 3 SETTINGS that control the Incremental Diff feature:

mini_diff controls the incremental diff functionality (on / off / on for Git only)
Valid values include:

true   –  always enable incremental diff (the DEFAULT) (Git or Not-Git)
"auto" –  enable  incremental diff for files in a Git repository (only)
false  –  disable incremental diff

git_diff_target controls the behavior of incremental diff for files in a Git repository
Valid values include:

"index" – diff against the Git index (aka staged for commit), (the DEFAULT)
"head"  – diff against the file at HEAD (aka last commit in checked out branch)