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.
Mousemap
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"} }
Keymap
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.
Caveats
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:
copy the Default mousemap from your unzipped Default package (PackageResourceViewer does not seem to be able to extract it, so do it manually, by adding .zip to the sublime-package if required)
paste it to your Default package folder
uncomment the entries you want to ignore
Related
I'd like to customize some of the Sublime Text 3 keybindings to mimic IntelliJ IDEA. One of them is opening a file from the current project, also known as Goto Anything in Sublime jargaon. I followed the instructions in this answer to find out that the default key binding for "Goto Anything" is ⌘ + p on a Mac, like so:
{ "keys": ["super+p"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} }
I added a new keybinding as follows:
[
{ "keys": ["shift+shift"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} }
]
It, however, doesn't work; pressing shift twice in rapid succession does precisely nothing. When I open the console, I see the following message:
Unable to open /Users/me/Library/Application Support/Sublime Text
3/Packages/Default/Default (OSX).sublime-keymap
According to this ticket, this message is harmless but misleading, and is just an indication that Sublime is opening a file.
What's wrong then?
OP here; I found this post in Sublime blog.
ST doesn't support using only modifier keys in a keybinding.
I am working with the sublime 3 text editor. I am modifying the User version of the keymap, however, it does not seem to be replacing the default keymap hotkeys. Specifically, in the Default keymap, I see the following assigned for the "copy" hotkey:
{ "keys": ["ctrl+insert"], "command": "copy" },
{ "keys": ["ctrl+c"], "command": "copy" },
There are two hotkeys assigned for the copy command, and I am not sure why. I use the latter command in my User keymap, but the hotkey is not working. The ctrl+insert hotkey is the one that is taking precedence.
Is there a way to modify the Default keymap for Sublime?
I don't see this conflict. But if you do, you can set a hotkey command to none if you don't want it to use.
{
"keys": ["ctrl+insert"],
"command": "none"
},
Has anyone found a way to have more complex pane layouts in Visual Studio Code, like those supported by Origami for Sublime? Layouts beyond splitting on the same axis are something that I really miss from Sublime.
like #pat-putnam says, VSCode now supports editor window splitting 🎉
To replicate the Origami experience, we need the Origami keyboard shortcuts too. To do this, paste the JSON snippet shown below into your VSCode keybindings.json.
You can quickly open keybindings.json in VSCode by pressing cmd+shift+p and then typing keyb and clicking the Preferences: Open Keyboard Shortcuts (JSON) completion hint that appears.
[
{
"key": "cmd+k up",
"command": "workbench.action.splitEditorUp"
},
{
"key": "cmd+k right",
"command": "workbench.action.splitEditorRight"
},
{
"key": "cmd+k down",
"command": "workbench.action.splitEditorDown"
},
{
"key": "cmd+k left",
"command": "workbench.action.splitEditorLeft"
},
{
"key": "cmd+k up",
"command": "-workbench.action.moveActiveEditorGroupUp"
},
{
"key": "cmd+k right",
"command": "-workbench.action.moveActiveEditorGroupRight"
},
{
"key": "cmd+k down",
"command": "-workbench.action.moveActiveEditorGroupDown"
},
{
"key": "cmd+k left",
"command": "-workbench.action.moveActiveEditorGroupLeft"
}
]
Note that if you have existing key bindings that you want to preserve, you should remove the [ and ] from the JSON snippet and just paste the config objects into your existing array.
These custom keybindings are for the editor-window-splitting functionality from Origami that I use most often. There are a few more Origami keyboard shortcuts beyond these four. It would be cool in the future to create a VSCode keybinding file that fully replicated the Origami keyboard shortcuts, and then release that as a VSCode keymap. Future work.
I recently revisited Visual Studio Code and found that you can now window split to your hearts content. Simply right click on any pane and select the appropriate split action.
How do I set up a keyboard shortcut to show/hide tabs and the status bar in Sublime Text 3?
At the moment I have to go View->Show/Hide Tabs. I'm using OSX. I have for instance
{ "keys": ["shift+space"], "command": "move", "args":
{"by": "characters", "forward": true},
in my key bindings user file which I set up (thanks to this answer!) to move the cursor one space forwards by pressing shift and space, and ideally I'm looking for something similar to show/hide tabs and the status bar.
In the ST console, enter sublime.log_commands(True). Then execute the command through the menu as normal. The command being executed (with arguments if applicable) will be displayed in the ST console. You can use the information there to create a key binding to the appropriate command.
I'm trying to mimic the functionality I set in Sublime Text that allows me to move the cursor much like 'j' or 'k' in VI. In the Windows world I guess it would be similar to a pgup/pgdn, however I'd like to just go up/down one line not one page.
Here's my bindings in Sublime Text that I'd like to mimic:
[
{"keys": ["ctrl+i"], "command": "move", "args": {"by": "lines", "forward": false}},
{ "keys": ["ctrl+k"], "command": "move", "args": {"by": "lines", "forward": true}}
]
Edit: As Logarr pointed out, the easier way to phrase this is I want to mimic the Up/Down arrow keys using ctrl+i and ctrl+k
There are already Vim extensions for Visual Studio. There is the free VsVim extension that works in Visual Studio 2010+ and ViEmu which works in Visual Studio 2003+ plus a few other applications.
If you just want to remap the up and down keys, then you can change the keyboard mapping. From Tools->Options find the Keyboard section. From there you can change the key bindings for Edit.LineDown and Edit.LineUp. You may want to select the Text Editor for the "Use new shortcut in:" setting so these changes only affect the text editor.
This would have been trivial if Microsoft hadn't ripped the macro functionality out of Visual Studio.
You could install AutoHotKey and write a simple script. This would have the advantage that you could apply these keymappings to any applications you like as well as Visual Studio.