From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12322 invoked by alias); 28 May 2015 11:42:28 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20231 Received: (qmail 12862 invoked from network); 28 May 2015 11:42:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=wWVUiPaH983sk9V/YmXPnfeQBB2m3/HYIIUduGOxNdk=; b=U5Fo8adUezpriZaINBZi3u1//A91lRWJBzKFmuRZJ7PEBe6ewU9KQZZ6+UJE9hYALG jrUzxSL1IEtobHOkJ1HvSXyJWxAuKue+/zXT0r/TrPxuSQ+zwvxn1SZRzbDgHBDHa/1M U9J8fhztuoN8FCOTQnUJ6NEAuzBq+E4mc1xcUpnbTpZ3AQIeLFoSQaSuJF/X+YtGv7Rg cBqV6x8kpau42kZdjrJE9WtSGiGUnh04fKLcmLIYiXmTxfmEorYyxG06oeQqKK8IVPIc /a5608GXXWrKJmZIryPkkY2IY/wpeh700NQ5RohwudxOS1Cwzyi579y5IL4X6+ED6jQ2 IK3A== X-Received: by 10.42.144.131 with SMTP id b3mr8910604icv.35.1432813341294; Thu, 28 May 2015 04:42:21 -0700 (PDT) MIME-Version: 1.0 Sender: arkanosis@gmail.com In-Reply-To: References: From: =?UTF-8?B?SsOpcsOpbWllIFJvcXVldA==?= Date: Thu, 28 May 2015 13:42:05 +0200 X-Google-Sender-Auth: ltLuyJHHEbjjOzZgbeL04yjk18Q Message-ID: Subject: Re: bracketed paste mode in xterm and urxvt To: Mikael Magnusson Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi everyone, I've kept this mail in my inbox for almost exactly four years (!), as a cool thing to look at when I'd have time. Obvious, I haven't had that much time since then, and I've only tested it today=E2=80=A6 What a mistake! This is with no doubt one of the most useful additions I've done to my config in years. Thanks Mikael! PS: below is the full quote of the original mail, which could be useful for people that weren't on this list four years ago. Or for people like me who didn't give it the attention it deserves. PS2: I've added screen-256color to my list of supported terminals, though technically I'm not sure it supports bracketed paste (and I'm running tmux anyway). ---------- Forwarded message ---------- From: Mikael Magnusson Date: 2011-05-22 21:16 GMT+02:00 Subject: bracketed paste mode in xterm and urxvt To: Zsh Users # create a new keymap to use while pasting bindkey -N paste # make everything in this keymap call our custom widget bindkey -R -M paste "^@"-"\M-^?" paste-insert # these are the codes sent around the pasted text in bracketed # paste mode. # do the first one with both -M viins and -M vicmd in vi mode bindkey '^[[200~' _start_paste bindkey -M paste '^[[201~' _end_paste # insert newlines rather than carriage returns when pasting newlines bindkey -M paste -s '^M' '^J' zle -N _start_paste zle -N _end_paste zle -N paste-insert _paste_insert # switch the active keymap to paste mode function _start_paste() { bindkey -A paste main } # go back to our normal keymap, and insert all the pasted text in the # command line. this has the nice effect of making the whole paste be # a single undo/redo event. function _end_paste() { #use bindkey -v here with vi mode probably. maybe you want to track #if you were in ins or cmd mode and restore the right one. bindkey -e LBUFFER+=3D$_paste_content unset _paste_content } function _paste_insert() { _paste_content+=3D$KEYS } function _zle_line_init() { # Tell terminal to send escape codes around pastes. [[ $TERM =3D=3D rxvt-unicode || $TERM =3D=3D xterm ]] && printf '\e[?2004= h' } function _zle_line_finish() { # Tell it to stop when we leave zle, so pasting in other programs # doesn't get the ^[[200~ codes around the pasted text. [[ $TERM =3D=3D rxvt-unicode || $TERM =3D=3D xterm ]] && printf '\e[?2004= l' } Alternatively, you can also do stuff to the text before inserting it, I have this additional stuff which lets me toggle a mode where all the pasted text is automatically quoted and a space is appended, which is useful when pasting (some) urls with ? and & and what have you. function _end_paste() { bindkey -e if [[ $_SPACE_AFTER_PASTE_QUOTE =3D 1 ]]; then LBUFFER+=3D${(q)_paste_content}' ' else LBUFFER+=3D$_paste_content fi unset _paste_content } function _spaceafterpastequote() { if [[ $_SPACE_AFTER_PASTE_QUOTE =3D 1 ]]; then _SPACE_AFTER_PASTE_QUOTE=3D0 zle -M "Not inserting a space after pastes, not quoting" else _SPACE_AFTER_PASTE_QUOTE=3D1 zle -M "Inserting a space after pastes and quoting" fi } zle -N _spaceafterpastequote # this is a custom wrapper that uses zkbd stuff, just use regular bindkey. zbindkey Control-Insert _spaceafterpastequote