How to define new keybindings with Visual Studio Code vim extension - vim

I've gone over the documentation and the looked at the question:
How to use vim (key-bindings) with Visual Studio Code vim extension and I still can't define new keys in the Vim extension for Visual Studio Code.
I'm trying two things in my settings.json. Trying to delete a full tab - instead of just a single space (like vim does) - with backspace.
"vim.insertModeKeyBindings": [
{
"before": "backspace",
"after": "shift+backspace"
}
]
And also to change between editor panes with space, w, w (like using a leader key):
"vim.keybindings": [
{
"key": ["space", "w", "w"],
"command": "workbench.action.navigateEditorGroups",
"when": "editorFocus"
}
]
But I can't get any of those to work.

Related

User key bindings in Sublime Text 3 doesn't work

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.

Conflict with sublime hotkey

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"
},

In VSCode, Exit Vim Insert Mode on Save

I use VSCode with the VSCodeVim extension. When in Insert Mode, I can press "CMD-S" to save. When I do, I would also like to exit Insert Mode automatically instead of pressing "ESC" as well.
Is this possible?
I was looking for a solution similar to this issue as well.
It appears that multiple commands cannot be mapped to key bindings in vscode; however, I've found an extension, macros, that let's you do this.
If you use the below steps with the macros extension, I believe that you'll have the solution you're looking for, until vscode implements something to address this feature request.
Step one, edit user settings with the below:
"macros": {
"saveAndExitVimInsertMode": [
"workbench.action.files.save",
"extension.vim_escape"
]
}
Step two, edit keyboard bindings:
{
"key": "cmd+s",
"command": "macros.saveAndExitVimInsertMode"
}
VSCodeVim extension supports insert mode key bindings. Here is a link to the extension readme that describes this feature.
Here is a snippet you could put in your settings.json.
"vim.insertModeKeyBindingsNonRecursive": [
{
"before": [ "<C-s>" ],
"commands": [
{ "command": "workbench.action.files.save" },
{ "command": "extension.vim_escape" }
]
}
],
After reloading your vscode window you can pressing ctrl+s to exit insert mode and save the file.
open Show Command Palette (Ctrl+Shift+P). enter 'open keyboard shortcut' ,
search 'extension.vim_escape' and edit it to be 2 times caps lock key.

Visual Studio Code pane management like Origami

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.

Move Cursor Up/Down Lines

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.

Resources