Skip to content

Instantly share code, notes, and snippets.

@leopay
Forked from jclosure/zle_cut_copy.zsh
Created August 12, 2021 05:33
Show Gist options
  • Select an option

  • Save leopay/9d5deb5a707d78e10ccab47a3b75aaf4 to your computer and use it in GitHub Desktop.

Select an option

Save leopay/9d5deb5a707d78e10ccab47a3b75aaf4 to your computer and use it in GitHub Desktop.
Fixing zsh's zle cut/copy keys for selected region to be identical to emacs (oh-my-zsh)
# Documented in the zsh manual: http://zsh.sourceforge.net/Guide/zshguide04.html
# under sections: "4.1.1: The simple facts" and "4.5.5: Keymaps"
# the default keymap for zle is "Emacs"
# The emacs keymap bindings for kill-region and copy-region-as-kill are a little off from emacs' defaults
# the zsh defaults are:
# M-w => kill-region
# M-W => copy-region-as-kill (that's M-S-w)
# C-w => backward-kill-word
# for emacs proper they should be:
# C-w => kill-region
# M-w => copy-region-as-kill
# in to .zshrc, add the following to rebind these:
source $ZSH/oh-my-zsh.sh
# add these below ^
# copy
# NOTE: \e == ^[ or ESC, which is bound to <alt> (Meta) in tty
bindkey "\ew" copy-region-as-kill
# cut
bindkey "\C-w" kill-region
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment