guyaloni guyaloni - 1 year ago 116
Git Question

Sublime text - shortcut for difftool

I want to add a shortcut in order to launch difftool for current file.

I added to

~/.config/sublime-text-3/Packages/UserDefault (Linux).sublime-keymap
the following entry:

{ "keys": ["ctrl+shift+g"], "command": "difftool" },

But it doesn't work.

I noticed that when I use the top menu (Tools->Git->This file->DiffTool) I see the following command in sublime console:

['git', 'difftool', '--', 'path-to-file']

I wonder how should I write the shortcut.

Answer Source

The Git package adds items to the menu by providing a Main.sublime-menu file that lists the menu items that it wants to add and what commands to invoke when they're selected. This will tell you the command you need to use and also the args that you need to provide to get the same functionality.

The easiest way to do that is to use PackageResourceViewer to open the resource so you don't have to hunt down the file manually.

Based on this, the shortcut you want would look like this (although this is formatted to display nicer here and could be all one line, etc):

    "keys": ["ctrl+shift+g"],
    "command": "git_raw",
    "args": {
        "command": "git difftool",
        "append_current_file": true,
        "may_change_files": false
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download