Bracketed paste for terminal vim

232 views
Skip to first unread message

Bruno Sutic

unread,
Jul 11, 2014, 5:51:44 AM7/11/14
to vim...@googlegroups.com
Hello!

I got really excited about one discovery, so I'd like to start a discussion and see if there is a possible fit into vim's feature roadmap.

So, apparently all modern terminals have a feature to tell programs when something is pasted.
Terminal does this by wrapping the paste content with sequences \e[200~ and \e[201~.

Because of this, terminal programs (specifically vim) *could* tell a difference when something is typed vs pasted.
This is nicely explained in the blog article here: http://cirw.in/blog/bracketed-paste

And this is not just theory - the same guy wrote a small plugin that enables this for vim, link: https://github.com/ConradIrwin/vim-bracketed-paste (it's less than 30 lines of viml)

I tried the plugin and it works great! (I'm on OS X, Terminal.app)
The punch line is: as a terminal vim user, I don't have to use `:set paste` ever again!

Now, what do you think: does this feature belong in the "plugin domain" or should it eventually be part of vim?

I'm just a user, so I couldn't help with any of that, but I like the feature so much - maybe my enthusiasm will infect someone else! :)

Bruno

Bram Moolenaar

unread,
Jul 11, 2014, 5:35:24 PM7/11/14
to Bruno Sutic, vim...@googlegroups.com
Sounds useful.

Since what version of xterm and screen is this supported? I suspect
older versions do not support it.

--
BEDEVERE: Look! It's the old man from scene 24 - what's he Doing here?
ARTHUR: He is the keeper of the Bridge. He asks each traveler five
questions ...
GALAHAD: Three questions.
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Bruno Sutic

unread,
Jul 11, 2014, 5:56:25 PM7/11/14
to vim...@googlegroups.com, bruno...@gmail.com

Hi Bram,
glad you think it's useful.

So I just googled it:
it turns out this is available in xterm for years. Here's the blog post from 2009 showing how to make it work with vim and xterm:
http://help.lockergnome.com/linux/Bug-504244-Vim-script-turn-xterm-bracketed-paste-mode--ftopict511918.html
I found other online resources mentioning this in 2010, 2011. But the above link is the earliest.

About screen - here's the patch from March 2013, so I guess it's been added there just recently:
https://lists.gnu.org/archive/html/screen-devel/2013-03/msg00000.html

Paul "LeoNerd" Evans

unread,
Jul 14, 2014, 8:18:27 AM7/14/14
to Bram Moolenaar, Bruno Sutic, vim...@googlegroups.com
On Fri, 11 Jul 2014 23:35:15 +0200
Bram Moolenaar <Br...@moolenaar.net> wrote:

> Since what version of xterm and screen is this supported? I suspect
> older versions do not support it.

It ultimately doesn't really matter. You send DECSM 2000 to ask for it
to be enabled. Either that works and you now get the extra keys, or you
don't, and you don't. Have the incoming code cope with the received
keys regardless, then it's just an optimisation.

--
Paul "LeoNerd" Evans

leo...@leonerd.org.uk
http://www.leonerd.org.uk/ | https://metacpan.org/author/PEVANS
signature.asc

Bram Moolenaar

unread,
Jul 14, 2014, 2:36:05 PM7/14/14
to Paul "LeoNerd" Evans, Bruno Sutic, vim...@googlegroups.com

Paul Evans wrote:

> On Fri, 11 Jul 2014 23:35:15 +0200
> Bram Moolenaar <Br...@moolenaar.net> wrote:
>
> > Since what version of xterm and screen is this supported? I suspect
> > older versions do not support it.
>
> It ultimately doesn't really matter. You send DECSM 2000 to ask for it
> to be enabled. Either that works and you now get the extra keys, or you
> don't, and you don't. Have the incoming code cope with the received
> keys regardless, then it's just an optimisation.

I rather stay on the safe side and only send an escape sequence when it
would do something useful. Keep in mind that whenever you run a shell
it has to be disabled. And also on exit, of course.

Simplest would be to recognize the xterm version being above a certain
level. I don't know how to check that for screen.

--
Yesterday, all my deadlines seemed so far away
now it looks as though it's freeze in four days
oh I believe in cvs..
[ CVS log "Beatles style" for FreeBSD ports/INDEX, Satoshi Asami ]
Reply all
Reply to author
Forward
0 new messages