我想创建一个Eclipse样式快捷方式 Ctrl + MouseClick 来打开函数/方法。 Sublime Text 3已经将此函数称为goto_definition
,但它绑定到 F12 。
但我不确定如何创建此绑定。我看了here的文档,但它太复杂了。你能用这个简单的键绑定来帮助我吗?
修改:根据这篇文章,我被告知要这样做:http://webtempest.com/better-definition-navigation-in-sublime-text-3/
[
{
"button": "button1",
"count": 1,
"modifiers": ["super", "shift"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
这似乎不起作用, ctrl + shift + click 什么都不执行。
答案 0 :(得分:227)
对于任何想要设置Eclipse样式goto定义的人,您需要在Sublime .sublime-mousemap
文件夹中创建User
文件。
Windows - 在Default (Windows).sublime-mousemap
%appdata%\Sublime Text 3\Packages\User
Linux - 在Default (Linux).sublime-mousemap
~/.config/sublime-text-3/Packages/User
Mac - 在Default (OSX).sublime-mousemap
~/Library/Application Support/Sublime Text 3/Packages/User
现在打开该文件并将以下配置放在
中[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
您可以根据需要更改modifiers
键。
由于Windows和Linux上的 Ctrl - button1
用于多项选择,如果你想要添加第二个修饰键,如 Alt 可能是一个好主意使用这两个功能:
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl", "alt"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
或者,您可以单独使用鼠标右键(button2
)和 Ctrl ,而不会干扰任何内置函数。
答案 1 :(得分:85)
设置转到alt + d的定义。从菜单首选项>键绑定 - 用户。然后添加以下JSON。
[
{ "keys": ["alt+d"], "command": "goto_definition" }
]
答案 2 :(得分:22)
如果您想查看如何进行正确的定义,请转到Sublime Text-> Preferences-> Key Bindings - Default并搜索您要覆盖的命令。
{ "keys": ["f12"], "command": "goto_definition" },
{ "keys": ["super+alt+down"], "command": "goto_definition" }
这两个显示在我的默认值中。
在Mac上我复制了第二个以覆盖。
在Sublime Text中 - >偏好 - >密钥绑定 - 用户我添加了
/* Beginning of File */
[
{
"keys": ["super+shift+i"], "command": "goto_definition"
}
]
/* End of File */
这将它绑定到mac上的Command + Shift + 1组合。
答案 3 :(得分:4)
ctrl!=超级Windows和Linux机器。
如果“Goto定义”的F12版本产生多个文件的结果,则“ctrl + shift + click”版本可能无法正常工作。用GoSublime包查看golang项目时发现了这个bug。
答案 4 :(得分:4)
在Mac上,您必须自己设置键绑定。只需转到
Sublime --> Preference --> Key Binding - User
并输入以下内容:
{ "keys": ["shift+command+m"], "command": "goto_definition" }
这将启用Shift + Command + M
的键绑定以启用goto定义。您可以将键绑定设置为您想要的任何内容。
答案 5 :(得分:0)
我使用Sublime便携版(适用于Windows),而且(将鼠标放在SublimeText\Data\Packages\User
文件夹中)对我不起作用。
我必须将mousemap文件放在SublimeText
文件夹中才能使其工作,其中Data\Packages\User
是我的便携版本的安装目录。 &
也是我找到keymap文件的地方。