guyaloni
guyaloni

Reputation: 5862

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.

Upvotes: 1

Views: 651

Answers (1)

OdatNurd
OdatNurd

Reputation: 22791

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
    }
}

If you don't already have existing key bindings, in order to use this you need to wrap the entire binding in a json array ([ and ]). Also note that all bindings need to be separated from each other with a comma.

Upvotes: 1

Related Questions