Sublime 3 - Set Key map for function Goto Definition

后端 未结 6 531
感情败类
感情败类 2020-12-04 05:06

I want to create an Eclipse style shortcut Ctrl+MouseClick to open the function/method. Sublime Text 3 has already this function called goto_defi

相关标签:
6条回答
  • 2020-12-04 05:08

    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.

    0 讨论(0)
  • 2020-12-04 05:18

    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.

    0 讨论(0)
  • 2020-12-04 05:19

    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" }
    ]
    
    0 讨论(0)
  • 2020-12-04 05:21

    I'm using Sublime portable version (for Windows) and this (placing the mousemap in SublimeText\Packages\User folder) did not work for me.

    I had to place the mousemap file in SublimeText\Data\Packages\User folder to get it to work where SublimeText is the installation directory for my portable version. Data\Packages\User is where I found the keymap file as well.

    0 讨论(0)
  • 2020-12-04 05:24

    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.

    0 讨论(0)
  • 2020-12-04 05:29

    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.

    0 讨论(0)
提交回复
热议问题