Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code - Ctrl+Backspace not working in Integrated Terminal

In the terminal (PowerShell) in Visual Studio Code, I'm trying to hit Ctrl+Backspace to delete last word, but it just adds ^W to end of the line, any ideas how to fix this? It works fine outside Visual Studio Code in PowerShell.

like image 546
Bjarte Avatar asked Oct 14 '18 20:10

Bjarte


2 Answers

ctrl+backspace is somehow mapped to ctrl+w in vscode integrated terminal (possibly a bug) and now we need to set ctrl+w binding to delete the word explicitly. weird right?

Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord

Note that this'll work for the current terminal session only.


To make this behaviour persistent, you can set it in profile Microsoft.PowerShell_profile.ps1 file. Create the file if it doesn't exist in your powershell version folder.

C:\Program Files\PowerShell\6\Microsoft.PowerShell_profile.ps1

write at the top

if ($env:TERM_PROGRAM -eq "vscode") {
  Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord
}

See more: Power up your PowerShell

Keybinding references:
https://learn.microsoft.com/en-gb/previous-versions/powershell/module/psreadline/Get-PSReadLineKeyHandler?view=powershell-5.0

https://learn.microsoft.com/en-gb/previous-versions/powershell/module/psreadline/set-psreadlinekeyhandler?view=powershell-5.0

like image 139
GorvGoyl Avatar answered Oct 09 '22 00:10

GorvGoyl


Based on the latest comment https://github.com/microsoft/vscode/issues/68167 I have modified JerryGoyal's answer so we don't have to modify bindings:

Put the following at the top of your Microsoft.PowerShell_profile.ps1 config file (type $profile in the terminal to find it, you might have to create one if it doesn't exist already)

if ($env:TERM_PROGRAM -eq "vscode") {
  Set-PSReadLineOption -EditMode Emacs
}

This works for me (vscode 1.43)

like image 3
noipster Avatar answered Oct 08 '22 22:10

noipster