Vim Keymap with Multiplicity on VS Code - visual-studio-code

I have remapped some vim keys in VS Code (using Vim emulation) but I can't manage to use them with multiplicity.
What this means is that when you normally press 3dd it deletes 3 lines. I have keymapped the normal version of the function dd like this
{
"before": ["<Leader>","c","l"],
"after": ["d","d"]
}
but it doesn't work if I press 3-leader-c-l.
How do you keymap keys with that functionality?

Related

Is there a way to add a keybinding shortcut that doesn't conflict with the existing ones (Visual Studio Code)

I'm trying to add a keyword shortcut that will close all the editors on the right side from the selected one. Somehow this is not by default in vscode on mac (or maybe just to me), I remember using it on window.
Anyway I created the shortcut based on cmd+w closing the selected editor. I thought using cmd + ->(right arrow) w. And it works perfectly for closing the editors. But it conflicts with the existing one cmd + -> that is used to go to the end of the line. How to make both to work.
I don't want to use other keybindings such as a unique one because these keys combination make sense to me. Well I tried also something like cmd+r w. Same problem, there is already a shortcut for cmd+r. And can't use it because it waits for the next key to be added.
There is already a command that does what you want (that is unound by default). Put this into your keybindings.json:
{
"key": "alt+right w", // choose your keybinding
"command": "workbench.action.closeEditorsToTheRight"
}
That's Alt+rightArrow and then a w (or whatever the Alt is on a mac. My guess is that Alt+rightArrow is not bound to anything on a mac.
Since there is no when clause to distinguish this command from Cmd+rightArrow or Cmd+R, using a unique keybinding like alt+right w (option+right w) is as close as you are going to get.

Vim VS Code Extension: How to remap "i" in normal mode to Escape key?

So I want to remap "i" to escape key since i find it easier to remember. But when I do this to settings.json of the VS Code:
"vim.normalModeKeyBindings": [
{
"before": [
"i"
],
"after": [
"<Esc>"
]
}
]
The "i" key is disabled and nothing happens. Just the "i" key in insert mode being disabled. Help, I'm new to vim.
In Vim, the i keybinding is used to go into insert mode from normal mode. The esc key is usually used to go into normal mode. Setting i as esc is definitely an anti-pattern. Usually people set CapsLock as esc key since it's nearer to the home row in keyboard and you don't have to reach as far as esc key, and since it's annoying sometimes.
I have also seen some people using jj over esc.
Nevertheless, to answer your question, just open Preferences: Open Keyboard Shortcut from command palette(Ctrl+Shift+p) and search for vim_escape. Then double click on it and enter the key i and then press enter again. That should get you the desired result.
Again, suggesting you to not go ahead with this remapping.
open keyboards shortcuts in vscode (ctrl + k, ctrl +s) then search for vim_insert you can change the "i" key to anything that you want.
Came from running VSCode vim keys in windows. microsoft/Powertoys can remap keys like escape to capslock as in this tutorial if one was content doing global keyboard mappings like on ubuntu.

Can VS Code input text when I type a rapid shift shift sequence?

So, my new keyboard doesn't have the pipe key, and I use it frequently (I'm learning elixir right now). I know that alt + 124 produces |, but it is a bit annoying to type it every time I want to use |> on elixir.
Is it possible to configure a shortcut (thought about something like shift shift) to insert |> in the editor?
Microsoft has its own tool to create custom layouts.
Microsoft Keyboard Layout Creator 1.4 Download.
Here is a brief how-to gracefully stolen from MakeUseOf
Open the Microsoft Keyboard Layout Creator app.
Head to File > Load Existing Keyboard.
Pick the layout you want to customize. You should make sure you pick the layout that matches your current keyboard setup, for example, QWERTY (U.S.).
Go to File > Save Source File As so you have a backup before you start making changes.
Set your new keyboard’s parameters in Project > Properties. You can pick a language and give the keyboard a name and description.
Click on a key and follow the on-screen prompt to remap it to a character of your choosing.
Assigning control keys combinations to input letters is not possible, AFAIK. Just set it so Shift+Something or to any 3rd level key. BTW, I am pretty sure your current 3rd level already has a pipe, to test it press the right Alt (also called AltGr) and press all the alphanumeric keys.
{
"key": "shift shift",
"command": "type",
"args": {
"text": "|>"
},
"when": "editorTextFocus"
}
Looks like using two modifier keys in rapid sequence will work soon. Commit merged: see Feature: Shift Shift, Ctrl Ctrl, Alt Alt Keybinds (Double press modifer keybind support)
Will be in v1.54 - works in the Insiders Build now.
You can define a keyboard shortcut
{
"key": "shift+alt+p",
"command": "type",
"args": { "text": "|>" },
"when": "editorTextFocus"
}
You can choose any key combo you like, see the docs

How can I make VSCode keybindings override keybindings for the terminal?

Here's an example:
In most terminals (including VSCode's) Control + M sends the Return key (carriage return) to the shell.
I would like instead for it to follow my defined keybinding in keybindings.json. In my case for example, Control + M would be used to build chords with other commands (e.g. Ctrl+M Ctrl+S to hide/show the side bar, whether I trigger it from the Panel in the terminal or anywhere else).
Is there a way to override terminal keybindings with VSCode ones?

Make selected block of text uppercase

Can I make a multi-line selection of text all capitals in Visual Studio Code?
In full Visual Studio it's CTRL+SHIFT+U to do this.
The extension that exists that I have seen only do non-multi-line blocks.
NOTE: THE UI OF VISUAL STUDIO CODE WHEN THIS QUESTION WAS ASKED (5 OR MORE YEARS AGO) HAS CHANGED.
The question is about how to make CTRL+SHIFT+U work in Visual Studio Code. Here is how to do it in version 1.57.1 or above.
Steps:
Open Visual Studio Code.
Press CTRL+SHIFT+P.
Type
open keyboard shortcuts
Select
Open keyboard shortcuts (json)
An editor will appear with keybindings.json file.
Place the following JSON in there and save:
[
{
"key": "ctrl+shift+u",
"command": "editor.action.transformToUppercase",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+l",
"command": "editor.action.transformToLowercase",
"when": "editorTextFocus"
}
]
Now CTRL+SHIFT+U will capitalise selected text, even if multi line. In the same way, CTRL+SHIFT+L will make selected text lowercase.
These commands are built into VS Code and no extensions are required to make them work.
Update August 2021
There is a UI to see and update keyboard shortcuts:
File-> Preferences -> Keyboard Shortcuts.
Find "Transform to Uppercase":
Click the + icon.
In the popup, press the desired key combination and hit enter:
Do the same for lower case.
Note
In the new versions (eg 1.57.x) of VS Code, Ctrl+Shift+L is a shortcut for bulk selecting all selected text occurrences. So you can use another combination, like Ctrl+Shift+/ etc.
Whenever you want to do something in VS Code and don't know how, it's a good idea to bring up the command palette with CTRL+SHIFT+P (CMD+SHIFT+P on mac), and try typing in a keyword for you want. Oftentimes the command will show up there so you don't have to go searching the net for how to do something.
Highlight the text you want to uppercase. Then hit CTRL+SHIFT+P to bring up the command palette. Then start typing the word "uppercase", and you'll see the Transform to Uppercase command. Click that and it will make your text uppercase.
Creator of the change-case extension here. I've updated the extension to support spanning lines.
To map the upper case command to a keybinding (e.g. CTRL+T+U), click File -> Preferences -> Keyboard shortcuts, and insert the following into the json config:
{
"key": "ctrl+t ctrl+u",
"command": "extension.changeCase.upper",
"when": "editorTextFocus"
}
EDIT:
With the November 2016 (release notes) update of VSCode, there is built-in support for converting to upper case and lower case via the commands editor.action.transformToUppercase and editor.action.transformToLowercase. These don't have default keybindings. They also work with multi-line blocks.
The change-case extension is still useful for other text transformations, e.g. camelCase, PascalCase, snake_case, kebab-case, etc.
Update on March 8, 2018 with Visual Studio Code 1.20.1 (mac)
It has been simplified quite a lot lately.
Very easy and straight forward now.
From "Code" -> "Preferences" -> "Keyboard shortcuts"
From the search box just search for "editor.action.transformTo",
You will see the screen like:
Click the "plus" sign at the left of each item,
it will prompt dialog for your to [press] you desired key-bindings,
after it showing that on the screen, just hit [Enter] to save.
In Linux and Mac there are not default shortcuts, so try to set your custom shortcut and be careful about don't choose a hotkey used (For example,
CTRL+U is taken for uncomment)
File-> Preferences -> Keyboard Shortcuts.
Type 'transfrom' in the search input to find transform shortcuts.
Edit your key combination.
In my case I have CTRL+U CTRL+U for transform to uppercase and CTRL+L CTRL+L for transform to lowercase
Just in case, for Mac instead of CTRL I used ⌘
Change letter case in Visual Studio Code
Updated answer
Show All Commands: Ctrl+Shift+P
and start typing "upper" or "lower" whichever command is highlighted, press Enter:
Note 1. The next time you use the function, it is usually enough to type the first letter of "upper" or "lower" words.
Note 2. You can also assign your own shortcut to these functions as they currently don't have any by default:
Original answer from 2017 (no longer valid for newer VSC versions)
To upper case: Ctrl+K, Ctrl+U
and to lower case: Ctrl+K, Ctrl+L.
Mnemonics:
K like the Keyboard
U like the Upper case
L like the Lower case
I think you can use
Select text
Ctrl+Shift+P
Enter Transform to Uppercase
Without defining keyboard shortcuts
Select the text you want capitalized
Open View->Command Palette (or Shift+Command+P)
Start typing "Transform to uppercase" and select that option
Voila!
At Sep 19 2018, these lines worked for me:
File-> Preferences -> Keyboard Shortcuts.
An editor will appear with keybindings.json file. Place the following JSON in there and save.
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+shift+u",
"command": "editor.action.transformToUppercase",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+l",
"command": "editor.action.transformToLowercase",
"when": "editorTextFocus"
},
]
I'm using the change-case extension and it works fine.
I defined the shortcuts:
{
"key": "ctrl+shift+u",
"command": "extension.changeCase.upper",
"when": "editorTextFocus"
},
{
"key": "ctrl+u",
"command": "extension.changeCase.lower",
"when": "editorTextFocus"
},
Standard keybinding for VS Code on macOS:
Selection to upper case ⌘+K, ⌘+U
and to lower case: ⌘+K, ⌘+L.
All key combinations can be opened with ⌘+K ⌘+S (like Keyboard Settings), where you can also search for specific key combinations.
Select the text to transform.
Use Ctrl + L to selected the whole line
Open Show all commands.
Linux and Windows: Ctrl + Shift + P, Mac: ⇧⌘P
Type in the command, e.g. lower, upper, title
Hit Enter
On a Mac, in Visual Studio Code, its very easy to add a key binding to perform this action, it is not linked to a hotkey combo as a default though.
In the menu bar, navigate to: Code > Preferences > Keyboard Shortcuts
In the search bar that comes up, type: Uppercase
A entry will come up called "Transform to Uppercase"
Hover your mouse over that entry and click the plus sign just to the left of the words "Transform to Uppercase"
In the box that comes up push the keys you want to bind that action to (Cmd +Shift + U is taken so I chose Ctrl + Shift + U) then press enter and you're good to go.
Note this is working at the time of this writing in May of 2021