In Linux, I can skip to the beginning of a command by pressing Ctrl-A , and Ctrl-E for jumping to the end of that. However, it is not compatible with Windows Termianl. How am I going to do that? Is it possible to add this shortcut to the list?
3 Answers
Assuming you've typed in a command (or used command history to bring it in as the current command), Home and End should get the cursor to the start or end, respectively, of the command line. (And Ctrl+← and Ctrl+→ will get you to the previous/next word in the command.)
Lemme start with: Yes, just using Home and End are definitely the easiest solutions here.
Is it possible to add this shortcut to the list?
You definitely can rebind ctrl+a
to send the same keys as Home (and similarly with ctrl+e
). You can add sendInput
actions to your settings, set up so that ctrl+a
/e
send the same set of characters that a home/end keypress would send:
"actions": [
{ "keys": "ctrl+a", "command": { "action": "sendInput", "input": "\u001b[H" }, "name": "home" },
{ "keys": "ctrl+e", "command": { "action": "sendInput", "input": "\u001b[E" }, "name": "end" },
]
I wouldn't totally recommend this though. Doing this will have ctrl+a
/e
permanently rebound to home/end - if you actually needed a ctrl+a
/e
in a different CLI app, you'd be out of luck. I also suspect that this won't work while you're running vim
. There might be more elaborate sequences you could send that would work, but 🤷
The keys are compatible with Windows Terminal; what they're not compatible with is the command shell running inside of that terminal. PowerShell, though, lets you define custom key bindings in a similar way to Bash, through your $profile
script:
Set-PSReadLineKeyHandler -Chord Ctrl-a -Function BeginningOfLine
Set-PSReadLineKeyHandler -Chord Ctrl-e -Function EndOfLine
Cmd.exe has no equivalent (sort of how like /bin/sh on Linux has no line editing at all).
Extra if you're still using the "default" PowerShell 5.0:
Set-PSReadlineKeyHandler -Chord Shift+SpaceBar -ScriptBlock {
[Microsoft.Powershell.PSConsoleReadLine]::Insert(" ")
}