How can I change the keymap to add selection caret on Sublime Text?
The default is ctrl + left mouse, I want to change to alt + left mouse, like PhpStorm's keymap.
How can I change the keymap to add selection caret on Sublime Text?
The default is ctrl + left mouse, I want to change to alt + left mouse, like PhpStorm's keymap.
In Sublime Text, sublime-keymap files are used for keyboard shortcuts and sublime-mousemap files for mouse actions. Your question is obviously about mouse shortcuts, but there are also some keyboard-related commands to add carets, so I will also talk about them.
Open your User mousemap at
Packages/User/Default (Linux/Windows).sublime-mousemap (*)
Add the entry:
{
"button": "button1", "modifiers": ["alt"],
"press_command": "drag_select",
"press_args": {"additive": true}
},
Change the button and modifiers for more tuning.
You can also use the lines and columns variants:
"press_args": {"by": "lines", "additive": true}
"press_args": {"by": "columns", "additive": true}
to select whole lines, or by columns. If you click without dragging in column selection, a caret will simply be added, so you can setup the columns variant, and only use the column selection when you need.
For more examples and variants, have a look at the default mousemap at
Packages/Default/Default (Linux/Windows).sublime-mousemap
(*) To access it directly from Sublime Text you can use the plugin PackageResourceViewer
If you prefer your own commands/shortcuts, create a entry in some sublime-commands file:
{
"caption": "Preferences: Mouse Bindings - Default",
"command": "open_file", "args":
{
"file": "${packages}/Default/Default ($platform).sublime-mousemap",
"contents": "[\n\t$0\n]\n" // start with "[]" if new file is created
}
}
and an entry in your keymap file (pick the shortcut you want)
{ "keys": ["super+alt+m"], "command": "open_file", "args": {"file": "${packages}/User/Default ($platform).sublime-mousemap", "contents": "[\n\t$0\n]\n"} }
Apart from the caret duplication that happens when you select multiple occurences, there are commands to duplicate the caret on the lines above or below.
Open your User keymap file and add the entries:
{ "keys": ["alt+shift+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["alt+shift+down"], "command": "select_lines", "args": {"forward": true} },
with the shortcuts you want.
In Sublime Text, there may be multiple shortcuts per command and adding a User shortcut does not deactivate Default shortcuts. If you want to deactivate some annoying default mouse behaviors, for example, you will have to: