How do I move the cursor to the beginning of the line in VSCode's terminal?
Asked Answered
T

6

16

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?

Titustityus answered 26/2, 2018 at 2:6 Comment(1)
Wow... I feel really dumb. I've been wondering how to get this working for the longest time, because none of the below answers work for me. Turns out I just needed to add bindkey -e to my .zshrc.Titustityus
R
7

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.

Razz answered 24/1, 2021 at 9:41 Comment(0)
S
6

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.

Sulfapyridine answered 1/5, 2020 at 22:36 Comment(0)
H
4

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.

Helminthology answered 28/8, 2019 at 22:7 Comment(1)
Do you know how to do that with linux?. In my case ubuntu Binonic 18.04.Okhotsk
T
2

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'

Technocracy answered 7/6, 2018 at 22:0 Comment(1)
Unfortunately this doesn’t appear to work when using the zsh shell.Helminthology
P
0

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.

Pleat answered 7/9, 2021 at 4:52 Comment(0)
E
0
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.

Eelgrass answered 7/10, 2021 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.