* Bracketed paste for zsh 4.3.x up to 5.0.8
@ 2015-08-21 6:57 Bart Schaefer
0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2015-08-21 6:57 UTC (permalink / raw)
To: zsh-users
A few ways to do this have been posted, starting back at workers/29898.
The most straightforward is probably this (condensed from Oliver and
Mikael's solutions in 29898 and 29899):
typeset -g main_keymap=emacs # or viins as you prefer
# Create keymap where all key strokes are self-insert-unmeta
bindkey -N paste
bindkey -R -M paste "^@"-"\M-^?" .self-insert-unmeta
# Swap keymaps during paste
paste-begin() { bindkey -A paste main }
zle -N paste-begin
paste-end() { bindkey -A ${main_keymap} main }
zle -N paste-end
bindkey -M paste '\e[201~' paste-end
bindkey '\e[200~' paste-begin
bindkey -a '\e[200~' paste-begin
# Turn on paste mode of terminal while editing
PROMPT+=$'%{\e[?2004h%}'
POSTEDIT=$'\e[?2004l'"$POSTEDIT"
However, if anything goes wrong with that you're dead in the water with
a keymap that won't let you execute any commands. So an alternate is
the following, which doesn't need to change keymaps. I've expanded it
to support stuffing the pasted text into a parameter if the name is
passed as an argument, and to replace the region if there is one,
both of which are features of the new builtin bracketed-paste widget
coming in the next release.
paste-end() { :; }
zle -N paste-end
paste-begin() {
local bp_PASTED
while zle .read-command; do
case "$REPLY" in
(paste-end) break;;
(*) bp_PASTED="$bp_PASTED$KEYS";;
esac
done
# This may not be necessary everywhere (fix newlines)
eval bp_PASTED=\$\{bp_PASTED:gs/$'\r'/$'\n'\}
if (( ARGC )); then
builtin typeset -g "$1"="$bp_PASTED"
else
if (( REGION_ACTIVE )); then
zle .kill-region
fi
LBUFFER="$LBUFFER$bp_PASTED"
fi
}
zle -N paste-begin
# Haven't really tested with vicmd,
# but should work with "bindkey -a"
bindkey '\e[200~' paste-begin
bindkey '\e[201~' paste-end
# Still need this too in older shells
PROMPT+=$'%{\e[?2004h%}'
POSTEDIT=$'\e[?2004l'"$POSTEDIT"
Hope someone finds this useful.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-08-21 6:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-21 6:57 Bracketed paste for zsh 4.3.x up to 5.0.8 Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).