Search code examples
keyboard-shortcutssublimetext2sublimetextsublimetext3

Sublime 3 - Set Key map for function Goto Definition


I want to create an Eclipse style shortcut Ctrl+MouseClick to open the function/method. Sublime Text 3 has already this function called goto_definition but it is bound to F12.

But I'm not sure how to create this binding. I looked here for documentation but it was too complex. Can you one help me out with this simple key binding?

Edit: Following this article I was told to do this: http://webtempest.com/better-definition-navigation-in-sublime-text-3/

[
    {
        "button": "button1", 
        "count": 1, 
        "modifiers": ["super", "shift"],
        "press_command": "drag_select",
        "command": "goto_definition"
    }
]

This doesn't seem to work, ctrl+shift+click executes nothing.


Solution

  • For anyone else who wants to set Eclipse style goto definition, you need to create .sublime-mousemap file in Sublime User folder.

    Windows - create Default (Windows).sublime-mousemap in %appdata%\Sublime Text 3\Packages\User

    Linux - create Default (Linux).sublime-mousemap in ~/.config/sublime-text-3/Packages/User

    Mac - create Default (OSX).sublime-mousemap in ~/Library/Application Support/Sublime Text 3/Packages/User

    Now open that file and put the following configuration inside

    [
        {
            "button": "button1", 
            "count": 1, 
            "modifiers": ["ctrl"],
            "press_command": "drag_select",
            "command": "goto_definition"
        }
    ]
    

    You can change modifiers key as you like.


    Since Ctrl-button1 on Windows and Linux is used for multiple selections, adding a second modifier key like Alt might be a good idea if you want to use both features:

    [
        {
            "button": "button1", 
            "count": 1, 
            "modifiers": ["ctrl", "alt"],
            "press_command": "drag_select",
            "command": "goto_definition"
        }
    ]
    

    Alternatively, you could use the right mouse button (button2) with Ctrl alone, and not interfere with any built-in functions.