VSCode Terminal command names for Up/Down Arrow hotkeys? [duplicate] - visual-studio-code

My current custom keybindings
{
"key": "alt+b",
"command": "workbench.action.terminal.sendSequence",
"when": "terminalFocus",
"args": {
"text": "\u0017"
}
},
{
"key": "alt+j",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u001bb" }
},
{
"key": "alt+l",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u001bf" }
},
{
"key": "alt+n",
"command": "workbench.action.terminal.sendSequence",
"when": "terminalFocus",
"args": {
"text": "\u001bd"
}
These work well with 1.45 update (integrated terminal update)
Reference - but I need more Information
I want to use 'ijkl' keys like 'wasd' gaming standard like my custom project intuiter
So My Idea is
Can we send sequence to terminal to show Previous Command/Next command (like when we click Up/Down Arrow)
moveToLineStart/moveToLineEnd sequence is removed with this update(sorry I can't find or make sequence) can we get this effect by sendSequence?

"Can we sendSequence to terminal to show Previous Command/Next Command (like when we click Up/Down Arrow)"
{
"key": "alt+x", // or whatever you choose
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u001b[A\n"
}
// 1 up arrow or previous command, works in cmd, git bash and powershell
// the \n at the end makes it execute the previous command immediately,
// leave it off if you don't want to do that
// \u000d, a carriage return, is equivalent to \n if you prefer to use that, so
// \u001b[A\u000d does the same thing as \u001b[A\n
> /** Carriage Return (Caret = ^M, C = \r) */
> export const CR = '\x0d';
{
"key": "alt+y", // or whatever you choose
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u001b[B\n"
}
// 1 down arrow
// see comment above about immediate command execution
For these arrow commands, see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
Functions using CSI , ordered by the final character(s)
CSI Ps A Cursor Up Ps Times (default = 1) (CUU).
CSI Ps B Cursor Down Ps Times (default = 1) (CUD).
This part \u001b[ is the escape sequence or CSI referred to in the document. Follow that with an A for cursur up (up arrow) so \u001b[A or follow the escape sequence with a B for a down arrow, so \u001b[B.
[Theoretically, you should be able to do \u001b[2A for 2 (the Ps part referred to above) up arrows at once but that never seems to work in vscode for me in vscode.]
{
"key": "ctrl+e",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0005" }, // move cursor to end of line, bash at least
"when": "terminalFocus"
},
{
"key": "ctrl+a",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0001" }, // move cursor to start of line, bash at least
"when": "terminalFocus"
},
I used the usual keybindings - at least in bash - for go to the start or end of the command line. See, e.g., http://teohm.com/blog/shortcuts-to-move-faster-in-bash-command-line/
From this document https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts
we see that Ctrl+A is :
/** Start of Heading (Caret = ^A) */ [that's Ctrl+A]
export const SOH = '\x01';
so I used \u0001 the unicode sequence to replace that listed \x01 which won't work with the sendSequence command.
Likewise, to send a Ctrl+E to the terminal for the go to the end of the command line, we see that Ctrl+E is :
/** Enquiry (Caret = ^E) */ [that's Ctrl+E]
export const ENQ = '\x05';
or unicode \u0005.
Now, your terminal shell might use something other than Ctrl+A and Ctrl+E for go to start/end of the command line. If my keybindings don't work for you, find out what your shell uses for go to start/end and see if they are in https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts

Related

VS Code - can I bind a character sequence to a function key?

I use VS Code with the Lean language, which supports Unicode characters. The Unicode characters are entered through sequences of ASCII characters. For example, to enter a universal quantifier you enter the five-character sequence \ a l l TAB. Is there any way in VS Code to bind that sequence to a function key so that I can say hit F1 and this is interpreted as entering the ASCII sequence?
I needed to bind a key in VSCode to a sequence of characters. Here's how to do that in VS Code 1.67.2:
Press ctrl+alt+P / cmd+alt+P to open the command palette.
Use the command "Preferences: Open Keyboard Shortcuts (JSON)"
Press the "Define Keybinding" button in the bottom right, or press cmd+K cmd+K / ctrl+K ctrl+K, or just type it in.
The following works for your case:
{
"key": "F1",
"command": "type",
"args": { "text": "\\all\t" },
"when": "editorTextFocus && !editorReadOnly"
},
and for my case
{
"key": "cmd+.",
"command": "type",
"args": { "text": "->" },
"when": "editorTextFocus && !editorReadOnly"
},
The binding will work as soon as you save the file.

select next occurence of a word when using multiple cursors

From the bellow screen shot you can see that I have placed multi-cursor one multiple lines.
I want the next occurrence of " to be selected on each line for each cursor. I know I can use ctrld for selecting next occurrence. But it only works for single cursor. What is the solution for multi-cursor?
with the extension Select By v0.11.0 and the command moveby.regex you can move multiple cursors based on a regular expression.
The regular expression can be fixed in the keybinding or asked from the user.
For fixed regex use a key binding like:
{
"key": "ctrl+f6", // or any other key combo
"when": "editorTextFocus",
"command": "moveby.regex",
"args": {
"regex": "\"",
"properties": ["next", "start"]
}
}
To ask for a regex use a key binding like:
{
"key": "ctrl+shift+f6", // or any other key combo
"when": "editorTextFocus",
"command": "moveby.regex",
"args": {
"ask": true,
"properties": ["next", "start"]
}
}
In the Inputbox enter the regular expression in a non-escaped form. In a JSON files you need to escape the " and \ characters.
In a later version the command selectby.regex will also support multi cursor.

Replace "< -" keystroke combination for a custom shortcut in VS Code

I was wondering how could I set a shortcut, for example CRTL+F for the keystrokes <- for a better experience programming with R language. Or even when I type - it prints out on my coding scripts the full <-.
I could set it in RStudio but couldn't find a way to do that in VS code. The shortcut options in VS Code are always linked to IDE commands, didn't help me at all.
Any ideas?
Or use this handy keyboard shortcut example with arguments from the doc pages
{
"key": "ctrl+f",
"command": "type",
"args": { "text": "<-" },
"when": "editorTextFocus && editorLangId == r"
},
You can also define a user snippet. For example, put this in your snippets\r.json file:
"assign": {
"prefix": "=",
"body": " <- ",
"description": "left arrow assignment"
}
Now, typing =Tab will insert <-.
Got it just by adding the below code to keybinding.json file:
// Place your key bindings in this file to override the defaults
[
{
"key": "oem_minus oem_minus",
"command": "type",
"args": {
"text": "<-"
},
"when": "editorTextFocus"
}
]
Worked perfectly. When I type -- it prints out <-.

Need VSCode sendSequence keybindings for previous command, next command, move to start of line, move to end of line terminal commands

My current custom keybindings
{
"key": "alt+b",
"command": "workbench.action.terminal.sendSequence",
"when": "terminalFocus",
"args": {
"text": "\u0017"
}
},
{
"key": "alt+j",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u001bb" }
},
{
"key": "alt+l",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u001bf" }
},
{
"key": "alt+n",
"command": "workbench.action.terminal.sendSequence",
"when": "terminalFocus",
"args": {
"text": "\u001bd"
}
These work well with 1.45 update (integrated terminal update)
Reference - but I need more Information
I want to use 'ijkl' keys like 'wasd' gaming standard like my custom project intuiter
So My Idea is
Can we send sequence to terminal to show Previous Command/Next command (like when we click Up/Down Arrow)
moveToLineStart/moveToLineEnd sequence is removed with this update(sorry I can't find or make sequence) can we get this effect by sendSequence?
"Can we sendSequence to terminal to show Previous Command/Next Command (like when we click Up/Down Arrow)"
{
"key": "alt+x", // or whatever you choose
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u001b[A\n"
}
// 1 up arrow or previous command, works in cmd, git bash and powershell
// the \n at the end makes it execute the previous command immediately,
// leave it off if you don't want to do that
// \u000d, a carriage return, is equivalent to \n if you prefer to use that, so
// \u001b[A\u000d does the same thing as \u001b[A\n
> /** Carriage Return (Caret = ^M, C = \r) */
> export const CR = '\x0d';
{
"key": "alt+y", // or whatever you choose
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u001b[B\n"
}
// 1 down arrow
// see comment above about immediate command execution
For these arrow commands, see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
Functions using CSI , ordered by the final character(s)
CSI Ps A Cursor Up Ps Times (default = 1) (CUU).
CSI Ps B Cursor Down Ps Times (default = 1) (CUD).
This part \u001b[ is the escape sequence or CSI referred to in the document. Follow that with an A for cursur up (up arrow) so \u001b[A or follow the escape sequence with a B for a down arrow, so \u001b[B.
[Theoretically, you should be able to do \u001b[2A for 2 (the Ps part referred to above) up arrows at once but that never seems to work in vscode for me in vscode.]
{
"key": "ctrl+e",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0005" }, // move cursor to end of line, bash at least
"when": "terminalFocus"
},
{
"key": "ctrl+a",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0001" }, // move cursor to start of line, bash at least
"when": "terminalFocus"
},
I used the usual keybindings - at least in bash - for go to the start or end of the command line. See, e.g., http://teohm.com/blog/shortcuts-to-move-faster-in-bash-command-line/
From this document https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts
we see that Ctrl+A is :
/** Start of Heading (Caret = ^A) */ [that's Ctrl+A]
export const SOH = '\x01';
so I used \u0001 the unicode sequence to replace that listed \x01 which won't work with the sendSequence command.
Likewise, to send a Ctrl+E to the terminal for the go to the end of the command line, we see that Ctrl+E is :
/** Enquiry (Caret = ^E) */ [that's Ctrl+E]
export const ENQ = '\x05';
or unicode \u0005.
Now, your terminal shell might use something other than Ctrl+A and Ctrl+E for go to start/end of the command line. If my keybindings don't work for you, find out what your shell uses for go to start/end and see if they are in https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts

VS Code: Shortcut to select or remove Block Comment with no text selected

I know there is a shortcut for comment and uncomment code block (SHIFT + ALT + A), but is there a way to quickly select (or even remove without select) block comment without using mouse or keyboard to select and press the delete/backspace button? For example:
/*
This is a large block of code with at least 50 lines of code!
:
:
*/
Is there a keyboard shortcut where I can place my cursor anywhere in the block comment and remove it in just a few keystrokes? Thanks!
You can set a macro to do this pretty easily.
First, use the excellent Select By extension (#rioV8) to select the text between and including the block comment markers /* and */. Put his into your settings:
"selectby.regexes": {
"BlockCommentSelect": {
"backward": "\/\\*",
"forward": "\\*\/",
"forwardInclude": true,
"backwardInclude": true,
"showSelection": true
}
},
You can use that with a keybinding like:
{
"key": "alt+s", // whatever keybinding you wish
"command": "selectby.regex",
"args": ["BlockCommentSelect"],
"when": "editorTextFocus"
},
You could stop here and use your keybinding to select the text and then Shift+Alt+A to toggle off the block comment.
Or you could add the selectby.regex1 to a macro and do it the selection and toggling off in one step. Here using the macro extension multi-command put this into your settings as well as the above selectby.regexes setting:
"multiCommand.commands": [
{
"command": "multiCommand.BlockCommentOff",
"sequence": [
{
"command": "selectby.regex",
"args": ["BlockCommentSelect"]
},
"editor.action.blockComment"
]
},
]
and then a keybinding to trigger that macro (in your keybindings.json):
{
"key": "shift+alt+A", // trigger the macro with whatever keybinding if you wish
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.BlockCommentOff" },
"when": "editorTextFocus && !editorHasSelection"
},
Here I used Shift+Alt+A to trigger the macro. And I used the when clause !editorHasSelection because if you have a selection maybe you want to block comment only that selection (inside another block comment!!).
Demos: (1) Just the first method where selectby selects your text and you manually toggle it off, and then (2) using the macro version to do it in one step.