Sublime Forum

Is there a way to toggle diff hunks for an entire file?

#1

I’d like to see diffs for an entire file, instead of just diff hunks. Is there a way to do this?

I checked the ST documentation on diffs and it looks like you can only toggle per line.

PS: Somehow, one of my files was showing all diff hunks exposed. Did I accidentally run a hidden keyboard command? Maybe just a glitch… anyway… I liked it… and it got me searching.

0 Likes

#2

How to toggle:

0 Likes

#3

Hi there,

how can I set key binding for this “show entire file”, it’s great if I can use keyboard shortcut.

0 Likes

#4

I have a workaround which utilizes some plugins.

    // show/hide all inline diff
    {
        "keys": ["ctrl+k", "ctrl+;"],
        "command": "chain",
        "args": {
            "commands": [
                // save cursors
                ["power_cursor_exit"],
                ["power_cursor_add"],
                // ...
                ["select_all"],
                ["toggle_inline_diff", { "prefer_hide": true }],
                ["deselect"],
                // load cursors
                ["power_cursor_activate"],
                ["power_cursor_exit"]
            ]
        }
    },
0 Likes

#5

I think you can toggle all the diffs with just one command (without needing 3 different packages, while also maintaining any user made selections and cursors)

import sublime
import sublime_plugin


class ToggleAllDiffsCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        sel = self.view.sel()
        old_sel = list(sel)
        sel.clear()
        sel.add(sublime.Region(0, self.view.size()))
        self.view.run_command("toggle_inline_diff", {"args": {"prefer_hide": True}})
        sel.clear()
        sel.add_all(old_sel)

Reference: https://github.com/AmjadHD/sublime_incremental_diff/blob/main/main.py#L26

And then you can bind toggle_all_diffs to whatever key you want.

2 Likes

#6

sure but i have those 3 plugins installed already so i don’t have to invent mine XD
but that implementation is tidy.

0 Likes

#7

Keybinding for noobs, I thought I was gonna have to provide some args, but no…

  {
    "keys": ["super+t", "super+d"],
    "command": "toggle_all_diffs"
  },

Nice one @UltraInstinct05 !

0 Likes