1

I'm using Arch Linux and Zsh. I usually keep several workspaces on and switch back-and-forth (using Ctrl+Alt+Up/Down). However, I notice that sometimes when I return to the terminal, it displays the following prompts:

enter image description here

It doesn't happen every time I switch; but it's quite often. And it's annoying.

I suppose these are up/down keys. Any ideas how to fix it?

Thanks in advance!

Anthony
  • 13

1 Answers1

0

You're right, this is from pressing Ctrl+Meta+Up/Down. Terminal send escape sequences to represent function keys and modifier combinations; see How do keyboard input and text output work? for an overview and Are there any linux terminals which can handle all key combinations? for more details that are relevant to this specific case.

Zsh has no way to know that certain presses of this key are not legitimate. The bug is either in your window manager (or the part of your desktop environment that handles the Ctrl+Meta+Up/Down key bindings) or in your terminal emulator. Probably in not in the terminal emulator because it shouldn't be seeing those key strokes at all: they should be captured by the program that has set them up as keyboard shortcuts.

The best you can do is zsh is set up a workaround: add a key binding for these key sequences that does nothing. This will only have an effect in zsh, not in other applications running in the terminal. The full character sequence is ␛[1;7A for Ctrl+Meta+Up and ␛[1;7B for Ctrl+Meta+Down where ␛ is an escape character (byte value 27). You can see this by pressing Ctrl+V and then the keystroke in zsh (the escape character shows up as ^[ on the terminal). By default, zsh reads ␛[1, sees that this escape sequence is not bound and stops reading here, then treats the following characters as ordinary insertions (there's no way to know when a key sequence ends, other than on a case by case basis).

bindkey -s '\e[1;7A' ''
bindkey -s '\e[1;7B' ''