1

When typing commands in Terminal I expect Ctrl+A to take me to the beginning of the line and Ctrl+E to the end of the line, for some reason though this seems to have stopped working at some point (I'm pretty sure it did in the past). Other command line shortcuts also do not work, although Ctrl+U does.

Instead the key sequence is inserted literally with a white highlight. Pressing backspace removes the ^A character pairs with a single press.

Screenshot of a Terminal window with Ctrl characters shown

I'm using ZSH on an M1 (2020) Mac Mini running Monterey 12.6 (21G115) and my command line tools are up to date.

My prompt looks like this:

# Zsh prompt
prompt='%F{green}%2~ %#%f '
export prompt

I've tried toggling Use Option As Meta Key in Terminal preferences without joy. I also have some modifications to ~/Library/KeyBindings/DefaultKeyBinding.dict but I tried removing them and it also didn't help.

EDIT

Thanks to Giles for helping me find a solution. Turns out I had the following in my ~/.zshenv, putting me in vi mode.

EDITOR="nvim"
export EDITOR

I was able fix my issue by removing those lines, or by adding bindkey -e below.

2

1 Answer 1

0

This looks like symptoms of zsh using vi-like bindings when you expect emacs-like bindings. With vi-like bindings, by default, most control characters insert themselves, but Ctrl+U erases the line (however, Ctrl+K inserts itself, like Ctrl+A and Ctrl+E).

With vi-like bindings, pressing Esc switches to vi command mode, where characters don't insert themselves anymore but instead run vi commands. Press i or a to go back to insert mode.

Zsh uses vi-like bindings if the EDITOR or VISUAL environment variable designates vi. You can force emacs-like bindings instead by putting the following line in your ~/.zshrc:

bindkey -e

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .