3

I want to disable Insert key completly in zsh. This key has no real use, and only annoys me when I hit it accidentally.

I found how to remove the binding for overwrite-mode

bindkey -r "^[[2~"

But now, when I actually hit Insert, instead of activationg overwrite-mode, it prints ~ on the cursor position.

Similar thing happens when I press F12, which is not bound to anything. It also prints ~.

How can I disable the Insert key completely (and F12, as well), so that pressing it does not do anything in zsh?

I don't want to disable Insert key globally, because some other programs may actually use it for useful purpose.

3

If you press a special key (such as Insert) which sends an escape sequence that is not recognized by zsh, it will do this. zsh will try to do something with the individual bytes of the escape sequence.

Looking at the result from bindkey, it seems that zsh has no suitable function which can be bound to a key to ignore it. But you could rebind Insert to an empty macro:

bindkey -s '\e[2~' ''

Likewise for F12. Press Ctrl+V F12 to see what escape sequence F12 sends, typically

bindkey -s '\e[24~' ''

According to the zshzle manual page, there is a limitation with this approach:

As well as ZLE commands, key sequences can be bound to other strings, by using `bindkey -s'. When such a sequence is read, the replacement string is pushed back as input, and the command reading process starts again using these fake keystrokes. This input can itself invoke urther replacement strings, but in order to detect loops the process will be stopped if there are twenty such replacements without a real command being read.

Binding to \a as I originally suggested does not appear to have this drawback, i.e.,

bindkey -s '\e[2~' '\a'
  • There is something funny happening, when I rebind the insert or F12 keys. When I press the rebound key 20 times in a row, I get an error: "zsh: string inserting another one too many times". – 400 the Cat Nov 4 '16 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.