更改多光标编辑快捷方式

Change multi-cursor editing shortcut

现在为了在 SublimeText3 中执行多光标编辑,我按 Ctrl 并单击我要编辑的地方。

我想更改此设置,所以我按 Alt(而不是 'Ctrl'),然后单击我要编辑的位置。

我觉得它应该在 Preferences -> Key Bindings 中的某处,但我找不到该选项。

如何更改此键绑定?

由于此处的绑定是针对鼠标按钮而不是键盘键,因此实际绑定不会存储在 sublime-keymap 文件中,而是存储在 sublime-mousemap 文件中。这是一种类似于 sublime-keymap 文件的格式,但它包括将命令映射到鼠标按钮、点击次数和修改键的功能。

Note: unlike a key binding, it's not possible to include a context key, so mouse bindings are an all-or-nothing affair; you can't set some to only apply in some circumstances and not others, for example.

为了修改鼠标绑定,您需要遵循与键绑定相同的一般过程,即在您的 User 包中创建一个具有适当名称的文件,其中包含您修改的内容绑定。没有任何允许您编辑鼠标映射的默认菜单项或命令选项板条目,因此您需要手动执行此操作。

Note: In the following file names, $PLATFORM is one of Windows, OSX or Linux depending on what platform you're on (case is important). Your question doesn't mention which platform you're on, so the instructions below assume Windows; change the platform as needed for your own uses. On OSX your bindings can include super to represent the command key, as they can in key bindings.

其中键绑定文件的名称是 Default ($PLATFORM).sublime-keymap,鼠标绑定的适当文件是 Default ($PLATFORM).sublime-mousemap。此外,与大多数设置默认行为的资源文件一样,基本文件存储在 Default 包中。

如果您使用View Package File 命令面板条目打开Default/Default (Windows).sublime-mousemap,您可以看到所有默认的鼠标绑定。您可能特别想在此处使用两个绑定,它们位于文件顶部附近的 "Basic drag select" 部分:

{
    "button": "button1", "count": 1, "modifiers": ["ctrl"],
    "press_command": "drag_select",
    "press_args": {"additive": true}
},
{
    "button": "button1", "count": 1, "modifiers": ["alt"],
    "press_command": "drag_select",
    "press_args": {"subtractive": true}
},

第一个绑定说当按下鼠标左键 (button1) 并按下 ctrl 键时,应该执行 drag_select 命令指示选择的参数应该是 added 到.

类似地,第二个绑定使用 alt 而不是 ctrl 并执行相同的命令,告诉它从选择中 subtract 而不是添加到它。

因此,Ctrl+左键单击 将插入符号(以及您拖过的任何文本)添加到选区,而 Alt+左键单击执行相反的操作并删除您拖过的插入符号和文本。

要实现您想要的更改,请创建一个包含以下内容的文件并将其另存为 Default (Windows).sublime-mousemap 在您的 User 包中(您可以使用 Preferences > Browse Packages 找到它的位置).

Note: If such a file already exists, add the two bindings here to the existing file instead of saving over it; in that case don't include the [ and ] characters, but make sure you paste the bindings in between the ones in the existing file along with the other bindings.

[
    {
        "button": "button1", "count": 1, "modifiers": ["alt"],
        "press_command": "drag_select",
        "press_args": {"additive": true}
    },
    {
        "button": "button1", "count": 1, "modifiers": ["ctrl"],
        "press_command": "drag_select",
        "press_args": {"subtractive": true}
    },
]

这是上面的两个绑定,但交换了修饰符。这使得 Alt 键添加选择和 Ctrl 删除选择,有效地逆转他们的行动。

如果您愿意,只需为 alt 添加绑定。但是,如果您这样做,ctrl 的绑定将仍然存在,这意味着您将有两个用于添加选择的绑定而没有用于删除选择的绑定。这可能会或可能不会引起关注,具体取决于您对该特定绑定的依赖程度。