Brian Schlenker
Brian Schlenker

Reputation: 5446

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

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?

Upvotes: 17

Views: 13631

Answers (6)

Casper Tsui
Casper Tsui

Reputation: 149

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.

Upvotes: 0

6rchid
6rchid

Reputation: 1301

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.

Upvotes: 0

Mark
Mark

Reputation: 183124

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.

Upvotes: 6

Adrian Macneil
Adrian Macneil

Reputation: 13273

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.

Upvotes: 6

sunknudsen
sunknudsen

Reputation: 7320

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.

Upvotes: 5

JCKE
JCKE

Reputation: 394

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'

Upvotes: 2

Related Questions