I have my terminal set to zsh, and in iTerm2 I can press ctrl+e
to move my cursor to the end of the line, and ctrl+a
to move to the beginning. In VSCode, this just prints out a literal ^E^A
. Is there a setting I need to allow terminal to respond to emacs style commands?
As was mentioned in a comment above:
Open ~/.zshrc
, and add this line to the end:
bindkey -e
I'm unclear why this works automatically for zsh in iTerm, but must be manually set to work with zsh in VSCode.
Try these keybindings:
{
"key": "ctrl+e",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0005" }, // move cursor to end of line, sends ctrl+e to terminal
"when": "terminalFocus"
},
{
"key": "ctrl+a",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0001" }, // move cursor to start of line, sends ctrl+a to terminal
"when": "terminalFocus"
},
Works in bash, I can't test in zsh but it should work.
Try starting Visual Studio Code from iTerm2 using code
.
That did it for me on... cmd+left and cmd+right work as expected.
Very strange though... opened an issue on GitHub.
I don't have zsh, but you may have luck with either the cursorHome
and cursorEnd
commands or the workbench.action.terminal.moveToLineStart
and workbench.action.terminal.moveToLineEnd
commands. Both can be set in either keyboard shortcuts or keybindings.json in the Command Palette - ctrl+shift+p
then search 'keyboard shortcuts'
Go to View, Command Palette, then search and select Preferences: Open Keyboard Shortcuts.
Now search for cursorLineStart
and give a keybinding shortcut to it i.e., Ctrl + DownArrow
. Similarly you can use cursorLineEnd
to move the caret to the end of the line.
For Emacs mode users
@Adrian Macneil's answer works.
–e
Binds all keys to the standard GNU Emacs-like bindings.
bindkey built-in command for tcsh: List all bound keys | IBM
For vi mode users
Set the following 2 lines to your ~/.zshrc.
bindkey "^a" vi-beginning-of-line
bindkey "^e" vi-end-of-line
Make sure bindkey
lines are placed after zle
commands.
Sorry that I don't have enough reputation to add comment under his thread.
© 2022 - 2024 — McMap. All rights reserved.
bindkey -e
to my .zshrc. – Titustityus