Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a couple of questions regarding the emacs-like keyboard bindings in Zsh. As background to all the questions: I have Emacs-like keybinding activated with bindkey -e (activated by default)

Copying and region highlighting:

In Emacs, if you run C-space (set-mark), select a region and then copy it using M-w, Emacs puts the region in the kill ring and stops selecting text (i.e. if I move the point, no more text is selected).

However, I can't get the same behavior in ZLE. Once I copy a region with M-W, the selection mode is still on, and if I move my cursor, the selection keeps changing.

Stop selection:

In Emacs, if I am selecting a region, and press C-g, the selection stops (the current mark is killed). In Zsh, by default, C-g starts a new line in the shell. So is there a ZLE command that I can bind to (maybe using something different from C-g) to stop an ongoing selection?

share|improve this question
up vote 4 down vote accepted

To deactivate the selection, run set-mark-command with a negative argument: ESC - Ctrl+Space.

To copy the region and deactivate the selection, write a function that performs the two actions, then declare it as a widget with zle -N and bind that widget to a key.

copy-region-as-kill-deactivate-mark () {
  zle copy-region-as-kill
  zle set-mark-command -n -1
zle -N copy-region-as-kill-deactivate-mark
bindkey '\ew' copy-region-as-kill-deactivate-mark
share|improve this answer
hi Gilles, when i run set-mark-command in zsh and move the cursor left/right, will it markup the selected text in black bgcolor... i am not seeing such highlighting in my zsh/gnome terminal... In bash as well, @unix.stackexchange.com/questions/11933/… Mikel has said, bash doesn't do highlighting.... – Madhavan Kumar Aug 6 '15 at 16:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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