Sublime 3 - Set Key map for function Goto Definition

140,844

Solution 1

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.

Solution 2

To set go to definition to alt + d. From the Menu Preferences > Key Bindings-User. And then add the following JSON.

[
    { "keys": ["alt+d"], "command": "goto_definition" }
]

Solution 3

If you want to see how to do a proper definition go into Sublime Text->Preferences->Key Bindings - Default and search for the command you want to override.

{ "keys": ["f12"], "command": "goto_definition" },
{ "keys": ["super+alt+down"], "command": "goto_definition" }

Those are two that show in my Default.

On Mac I copied the second to override.

in Sublime Text -> Preferences -> Key Bindings - User I added this

/* Beginning of File */

[
    {
        "keys": ["super+shift+i"], "command": "goto_definition" 
    }
]

/* End of File */

This binds it to the Command + Shift + 1 combination on mac.

Solution 4

On a mac you have to set keybinding yourself. Simply go to

Sublime --> Preference --> Key Binding - User  

and input the following:

{ "keys": ["shift+command+m"], "command": "goto_definition" }

This will enable keybinding of Shift + Command + M to enable goto definition. You can set the keybinding to anything you would like of course.

Solution 5

ctrl != super on windows and linux machines.

If the F12 version of "Goto Definition" produces results of several files, the "ctrl + shift + click" version might not work well. I found that bug when viewing golang project with GoSublime package.

Share:
140,844

Related videos on Youtube

Kivylius
Author by

Kivylius

Just an average programmer. I'm not the best I love to program &*%^$ the rest.

Updated on July 31, 2020

Comments

  • Kivylius
    Kivylius almost 4 years

    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.

    • skuroda
      skuroda about 11 years
      super is the windows key for Windows and Linux and the command key for OS X, not control. Try that and see if you get the behavior you want.
  • Magico
    Magico almost 11 years
    CMD+SHIFT+MOUSE1 does not work! what the right sintax to make click on con GoTo Definition?
  • Kivylius
    Kivylius almost 11 years
    This seems like the correct answer, but i did everything you said and still It not working i'm ctrl + click and its not doing anything, I get an error Unable to parse binding
  • Boris Brdarić
    Boris Brdarić almost 11 years
    have you checked configuration file name? can you post error screenshot somewhere?
  • Tom
    Tom over 10 years
    Does anyone know how you'd right click for this? I was able to add to a Context.sublime-menu file the command but couldn't figure out how to pass in the args for the currently selected text...Or line...I searched for a good while trying to find documentation (and did try "args": "drag_select") but couldn't figure it out. I'd rather right click and jump to definition though this does work great! Thanks.
  • mbokil
    mbokil over 10 years
    Not certain why I got down voted but this solution is working perfectly for me on Sublime 3.
  • Charles Roper
    Charles Roper over 10 years
    You probably got downvoted because the original question asked "I want to create a Eclipse style shorcut Ctrl+MouseClick to open the function/method". I found your answer useful inasmuch as I'm not interested in the mouse shortcut version, so I've upvoted. :)
  • user3388884
    user3388884 almost 10 years
    Could I also bind the enter key to this so I don't have to manually press it everytime i ctrl + click?
  • uday
    uday about 9 years
    seems like better option than the cmd+opt+down
  • IROEGBU
    IROEGBU almost 9 years
    Possible to use button1 instead of d... so, we have like "alt" + "button"
  • Ivan Chau
    Ivan Chau almost 9 years
    @Magico Required GoSublime install and it may only work for Golang project. GoSublime: Godoc/Goto Definition ctrl+dot,ctrl+g or ctrl+shift+left-click on Windows. Replace ctrl as command on Mac.
  • Alexander Solonik
    Alexander Solonik over 8 years
    @BorisSamardžija , also how do i make the above script look for the function definition in my current file rather than jumping to other external files.
  • EvgenyKolyakov
    EvgenyKolyakov about 3 years
    On linux & windows change shift+command+m to shift+control+m