Is it possible to map `alt+s` to escape in VSCode Vim? - visual-studio-code

I've been using alt+s to escape in vim for a while. I'm now considering to try VSCode with its vim plugin. Is it possible to map alt+s to extension.vim_escape? Currently, alt+s opens "Selection" from the top menu bar.
I have tried adding the following to keybindings.json
{
"key": "alt+s",
"command": "extension.vim_escape"
}
as well as the following to settings.json
"vim.insertModeKeyBindings": [
{
"before": ["alt+s"],
"after": ["<Esc>"]
}
],

What worked for me was putting this binding into keybindings.json and reloading the editor.
[
{
"key": "alt+s",
"command": "extension.vim_escape",
"when": "editorTextFocus && vim.active && vim.mode == 'Insert'"
}
]

Related

How to enable <C-k> to "scroll up" in code sugguestions/hints with vscode vim instead of using arrow keys?

VScodevim has extension.vim_ctrl+j by default mapped to Ctrl+j which allows you do navigate down pop-up code suggestion windows (triggered by hitting Ctrl+Space in insert mode) like this:
It also has extension.vim_ctrl+k mapped to Ctrl+k but this binding down not work, so I cannot scroll up pop-up code suggestion windows. in insert mode defaults to entering a digraph but simply adding something like this
{
"before": ["<C-k>"],
"after": ["extension.vim_ctrl+k"]
}
to my settings.json does not work since although it removes the digraph functionality, from what I understand, whenever I now press Ctrl+k in insert mode, VSCode will consult the settings.json, find the mapping of to "extension.vim_ctrl+k" which points it back to settings.json in a sort of infinite loop.
:h i_ctrl-j in vim reveals this keybind to be mapped to "Begin new line" so it seems VScode interprets "Begin new line" as navigating down a pop-up window in insert mode instead of it's usual vim behaviour of creating a new line and moving the cursor there, although not sure this is how it works. In any case, I could not find an equivalent vim command that perhaps VSCode could use to scroll up in pop-up windows. Any help would be much appreciated!
I got this working by copying the existing default keybinds for ctrl+p and ctrl+n which are used throughout VSCode by default for scrolling up and down.
I've used alt here in my keybinds.json file but you can easily replace it with ctrl to achieve what you want
keybinds.json
// Down Motion
{
"key": "alt+j",
"command": "cursorDown",
"when": "textInputFocus"
},
{
"key": "alt+j",
"command": "showNextParameterHint",
"when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
},
{
"key": "alt+j",
"command": "selectNextSuggestion",
"when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
},
{
"key": "alt+j",
"command": "list.focusDown",
"when": "listFocus && !inputFocus"
},
{
"key": "alt+j",
"command": "workbench.action.quickOpenSelectNext",
"when": "inQuickOpen"
},
// Up Motion
{
"key": "alt+k",
"command": "cursorUp",
"when": "textInputFocus"
},
{
"key": "alt+k",
"command": "showPrevParameterHint",
"when": "editorFocus && parameterHintsMultipleSignatures && parameterHintsVisible"
},
{
"key": "alt+k",
"command": "selectPrevSuggestion",
"when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
},
{
"key": "alt+k",
"command": "list.focusUp",
"when": "listFocus && !inputFocus"
},
{
"key": "alt+k",
"command": "workbench.action.quickOpenSelectPrevious",
"when": "inQuickOpen"
}

`Ctrl+Del` to delete following whitespaces (like in VS201X)

In VS2017 when use Ctrl+Del to delete a word, it will auto delete any following whitespaces.
Is it available to config VSC to working same way?
I don't think there is any built-in setting to do that. You would either have to just hit Ctrl-Del twice
or set up a macro to run that command twice.
Using the multi-command macro extension, puth is into settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.deleteWordAndWhieSpaceRight",
"sequence": [
"deleteWordRight",
"deleteWordRight",
]
}
]
and in keybindings.json:
{
"key": "ctrl+delete",
"command": "-deleteWordRight",
"when": "textInputFocus && !editorReadonly"
},
{
"key": "ctrl+delete",
"command": "multiCommand.deleteWordAndWhieSpaceRight",
"when": "textInputFocus && !editorReadonly"
},

vscode: how to clear both the console and the terminal using the same shortcut?

I'm looking for a shortcut that would clear the debug console + the terminal, and that would work when my cursor is on the editor.
I tried this code in the keybindings.json which only works for the terminal, and when the cursor is on the terminal (unless I removed the "when" part). But in any case this doesn't clear the debug console.
{
"key": "ctrl+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus"
},
{
"key": "ctrl+k",
"command": "workbench.debug.panel.action.clearReplAction",
"when": "inDebugRepl"
},
You will probably have to use a macro extension like multi-command that will allow you to run multiple commands.
In your settings.json:
"multiCommand.commands": [
{
"command": "multiCommand.clearTerminalandDebugConsole",
"sequence": [
"workbench.action.terminal.clear",
"workbench.debug.panel.action.clearReplAction"
]
}
]
and in keybindings.json:
{
"key": "ctrl+alt+k",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.clearTerminalandDebugConsole" },
// below since you wanted it to work with editor focus
"when": "editorTextFocus"
},
You used Ctrl-K but that is a sequence used in many already-bound conflicting commands, so I used Ctrl-Alt-K.

VS Code execute current line or selection to in the integrated console

This old Emacs user, who is used to elpy, is attempting to move onto VSCode with Scala & more specifically Ammonite repl.
I used Ctrl+' to open the integrated terminal & all I have to do is type amm on the bash shell (ubuntu) to open the repl; however, I still miss being able to send the either the line or selection from the editor to integrated shell with Ctrl+Enter.
I guess this means a bit of coding. Where can I start? Has anyone accomplished similar?
Thanks much,
If you already have your terminal and REPL open, there is a built in command called "Run Selected Text in Active Terminal" / workbench.action.terminal.runSelectedText.
It has no default keybinding, so you need to set it yourself. Something like this would work:
{
"key": "ctrl+enter",
"command": "workbench.action.terminal.runSelectedText",
"when": "editorTextFocus && editorHasSelection"
}
Actually, I found that adding VSCode Macros extension does the job:
I just changed settings.json:
{
"window.zoomLevel": 1,
"editor.fontSize": 11,
"terminal.integrated.fontSize": 11,
"macros": {
"execCurLn": [
"cursorUp",
"expandLineSelection",
"workbench.action.terminal.runSelectedText",
"cancelSelection"
]
}
}
and added (1st part is pure #kwood & thank u again) to keybindings.json
{
"key": "ctrl+enter",
"command": "workbench.action.terminal.runSelectedText",
"when": "editorTextFocus && editorHasSelection"
}
{
"key": "ctrl+enter",
"command": "macros.execCurLn",
"when": "editorTextFocus && !editorHasSelection"
},
{ "key": "ctrl+`", "command": "workbench.action.terminal.focus"},
{ "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
Open the command palette with CTRL+SHIFT+P and look for Terminal: Run Selected Text In Active Terminal. On the left you will see the key binding or a wheel engine to set the binding.
follow another post VS Code move to next line on run ctrl + enter, to run current line then cursor down, avoiding running next line unexpectedly
in settings.json, add
"macros": {
"pythonExecSelectionAndCursorDown": [
"python.execSelectionInTerminal",
"cursorDown",
]
}
in keybindings.json, add
{
"key": "ctrl+enter",
"command": "macros.pythonExecSelectionAndCursorDown",
"when": "editorTextFocus && editorLangId == 'python'"
},

Jump to bottom of Integrated Terminal when running PowerShell

I use Visual Studio Code to develop with PowerShell on a regular basis. I frequently will test out a single line of code by hitting F8 (aka. Run Selection). However, if I've scrolled up from the bottom of the Integrated Terminal, hitting F8 doesn't cause the Integrated Terminal to scroll down to the end of its buffer.
How can I configure VSCode, with the PowerShell Extension, to jump to the end of the Integrated Terminal buffer, when I execute the Run Selection command?
I don't see a built-in way to do this, but you should be able to use the macros extension. Add the following to the end of settings.json:
"macros": {
"PowerShellRunSelection": [
"workbench.action.terminal.scrollToBottom",
"PowerShell.RunSelection"
]
}
Then add a keybinding to keybindings.json as follows:
{
"key": "f8",
"command": "macros.PowerShellRunSelection",
"when": "editorTextFocus && editorLangId == 'powershell'"
}
Here is my setting for both f5 and f8
settings.json
"macros": {
"PowershellRunSelection": [
"workbench.action.terminal.scrollToBottom",
"PowerShell.RunSelection"
],
"PowershellRun": [
"workbench.action.terminal.scrollToBottom",
"workbench.action.debug.start"
]
}
keybindings.json
{
"key": "f8",
"command": "macros.PowershellRunSelection",
"when": "editorTextFocus && editorLangId == 'powershell'"
},
{
"key": "f5",
"command": "macros.PowershellRun",
"when": "editorTextFocus && editorLangId == 'powershell'"
}