Skip to content

Instantly share code, notes, and snippets.

@hyrious
Last active August 8, 2025 02:13
Show Gist options
  • Save hyrious/3f1b73279e011ff8aa7e92da2bd326de to your computer and use it in GitHub Desktop.
Save hyrious/3f1b73279e011ff8aa7e92da2bd326de to your computer and use it in GitHub Desktop.
Copy diff without leading +
import sublime
import sublime_plugin
import re
class CopyDiffCommand(sublime_plugin.TextCommand):
def run(self, edit):
chunks = []
for region in self.view.sel():
chunks.append(self.view.substr(region))
text = '\n'.join(chunks)
text = re.sub(r"^[-+ ]", '', text, flags=re.M)
sublime.set_clipboard(text)
sublime.status_message('Copied ' + text)
def is_enabled(self):
return 'source.diff' in self.view.scope_name(0)
[
{ "keys": ["super+c"], "command": "copy_diff", "context": [{ "key": "selector", "operand": "source.diff", "operator": "equal", "match_all": true } ] }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment