Sublime Forum

Diff/merge two views

#1

I often need to diff two files that are already opened in Sublime so I created a simple Merge plugin (available in the repo)

For simplicity, this command will diff/merge the last two selected files.

To use: click on view A, click on view B, press Ctrl+Alt+D. WinMerge will be launched with files A and B.

You need to have WinMerge installed: winmerge.org/

0 Likes

#2

Just thought I’d say thanks and give you a bump. Works great :smile:

0 Likes

#3

Hi

Works well in ST’s Single-Pane mode (i.e. two tabs in same pane being compared). Couldn’t get it to work in multi-pane layout with one file from each of two panes being compared though - ST hangs and WinMerge not launched. (I use ST 1.2.2, WinMerge 2.12.4 on W7HP).

Still, works great in Single-Pane mode. Thanks!

Rgds
JG

0 Likes

#4

Thanks for the bug report - I changed the approach to make it work across different panes and windows.

The updated version is available on the repo.

0 Likes

#5

Gonna grab it now. Thanks!

Best,
JG

0 Likes

#6

I tweaked this plugin so it would work with Sublime Text 2 on my machine. Here’s the code:

import os
from subprocess import Popen

import sublime
import sublime_plugin

WINMERGE    = '"%s\WinMerge\WinMergeU.exe"' % os.environ'ProgramFiles(X86)']
FILES       = [None, None]

class WinmergeCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        print WINMERGE
        Popen('%s /e /ul /ur "%s" "%s"' % (WINMERGE, FILES[0], FILES[1]))

class WinmergeTracker(sublime_plugin.EventListener):
    
    def on_activated(self, view):
        if view.file_name() != FILES[0]:
            FILES[1] = FILES[0]
            FILES[0] = view.file_name()

And here’s the keybinding I used:

{ "keys": "ctrl+shift+d"], "command": "winmerge" }

This is my first time working with a sublime plugin or python, so if there is any room for improvement, please post!

0 Likes

#7

Hi guys,

can you tweak the plugin to support Apple FileMerge? Filemerge comes free with XCode…

Is there a way to use it as a replacement for the standard “Diff” Menu?

0 Likes

#9

https://github.com/thtliife/FileMerge
It is still only beta, but works fine on OSX for me, with ST3
Should be available in Package Control pretty soon…

0 Likes