Supporting xterm-bracketed-paste

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Supporting xterm-bracketed-paste

Matteo Landi-2
Hello everyone,

Only recently I got to learn about 'xterm-bracketed-paste' when all of a sudden CMD-V-ing had stopped working on my Mac, and while I found a solution that worked with my setup [0], I am still not 100% sure the solution I found is the correct one -- so here I am asking.

Question: is it expected that users create insert-mode mappings to support bracketed-paste?  Or, once enabled, proper-pasting should just work out of the box?  Because it looks like everything it's working fine when pasting in normal mode, but when in insert mode, the result is a mess (i.e. insert-mode mappings are executed, and autoindent screws indentation).

Example: say you had the following copied in the OS clipboard:

function foo() {
  while (true) {
    console.log('infinite!');
  }
}

And you started vim with: `vim -u NONE -c 'inoremap { {}'`; in normal mode, you press CMD-V and end up with the following buffer:

function foo() {
  while (true) {
    console.log('infinite!');
  }
}

~

Enter now insert mode, press CMD-V, and your buffer would look like the following (imaps and autoindent messed with the pasted content):

function foo() {
  while (true) {
    console.log('infinite!');
  }
}
function foo() {} 
  while (true) {} 
      console.log('infinite!');
        }
        }

~

Thanks,
Matteo

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Supporting xterm-bracketed-paste

Lifepillar
On 06/05/2018 17:45, Matteo Landi wrote:

> Hello everyone,
>
> Only recently I got to learn about 'xterm-bracketed-paste' when all of a
> sudden CMD-V-ing had stopped working on my Mac, and while I found a
> solution that worked with my setup [0], I am still not 100% sure the
> solution I found is the correct one -- so here I am asking.
>
> Question: is it expected that users create insert-mode mappings to
> support bracketed-paste?  Or, once enabled, proper-pasting should just
> work out of the box?  Because it looks like everything it's working fine
> when pasting in normal mode, but when in insert mode, the result is a
> mess (i.e. insert-mode mappings are executed, and autoindent screws
> indentation).
>
> Example: say you had the following copied in the OS clipboard:
>
> function foo() {
>    while (true) {
>      console.log('infinite!');
>    }
> }
>
> And you started vim with: `vim -u NONE -c 'inoremap { {}'`; in normal
> mode, you press CMD-V and end up with the following buffer:
>
> function foo() {
>    while (true) {
>      console.log('infinite!');
>    }
> }
>
> ~
>
> Enter now insert mode, press CMD-V, and your buffer would look like the
> following (imaps and autoindent messed with the pasted content):
>
> function foo() {
>    while (true) {
>      console.log('infinite!');
>    }
> }
> function foo() {}
>    while (true) {}
>        console.log('infinite!');
>          }
>          }

I cannot reproduce the indentation issue. Besides, if I add -N to Vim's
options, I cannot reproduce the issue altogether. Is nocompatible set
in your Vim? I am using Vim 8.0.1750 on macOS 10.13.

Life.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Supporting xterm-bracketed-paste

Matteo Landi-2
I cannot reproduce the indentation issue. Besides, if I add -N to Vim's

I just realized the vim command in my previous message did not include 'set autoindent': try with `vim -u NONE  -c 'inoremap { {} | set autoindent'`.

Is nocompatible set in your Vim? I am using Vim 8.0.1750 on macOS 10.13.

Yes.

:echo &compatible
0

Thanks,
Matteo

On Sun, May 6, 2018 at 10:37 PM, Lifepillar <[hidden email]> wrote:
On 06/05/2018 17:45, Matteo Landi wrote:
Hello everyone,

Only recently I got to learn about 'xterm-bracketed-paste' when all of a sudden CMD-V-ing had stopped working on my Mac, and while I found a solution that worked with my setup [0], I am still not 100% sure the solution I found is the correct one -- so here I am asking.

Question: is it expected that users create insert-mode mappings to support bracketed-paste?  Or, once enabled, proper-pasting should just work out of the box?  Because it looks like everything it's working fine when pasting in normal mode, but when in insert mode, the result is a mess (i.e. insert-mode mappings are executed, and autoindent screws indentation).

Example: say you had the following copied in the OS clipboard:

function foo() {
   while (true) {
     console.log('infinite!');
   }
}

And you started vim with: `vim -u NONE -c 'inoremap { {}'`; in normal mode, you press CMD-V and end up with the following buffer:

function foo() {
   while (true) {
     console.log('infinite!');
   }
}

~

Enter now insert mode, press CMD-V, and your buffer would look like the following (imaps and autoindent messed with the pasted content):

function foo() {
   while (true) {
     console.log('infinite!');
   }
}
function foo() {}
   while (true) {}
       console.log('infinite!');
         }
         }

I cannot reproduce the indentation issue. Besides, if I add -N to Vim's
options, I cannot reproduce the issue altogether. Is nocompatible set
in your Vim? I am using Vim 8.0.1750 on macOS 10.13.

Life.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Supporting xterm-bracketed-paste

Matteo Landi-2
if I add -N to Vim's options, I cannot reproduce the issue altogether.

Ok, as Life pointed out earlier, pasting works fine with `vim -u NONE -N foo.js  -c 'inoremap { {} | set autoindent'`, which means the problem might be in the.vimrc or in one of the linked plugins.  Any hint on how to narrow down the search for the misconfigured setting?

Thanks,
Matteo

On Mon, May 7, 2018 at 7:36 AM, Matteo Landi <[hidden email]> wrote:
I cannot reproduce the indentation issue. Besides, if I add -N to Vim's

I just realized the vim command in my previous message did not include 'set autoindent': try with `vim -u NONE  -c 'inoremap { {} | set autoindent'`.

Is nocompatible set in your Vim? I am using Vim 8.0.1750 on macOS 10.13.

Yes.

:echo &compatible
0

Thanks,
Matteo

On Sun, May 6, 2018 at 10:37 PM, Lifepillar <[hidden email]> wrote:
On 06/05/2018 17:45, Matteo Landi wrote:
Hello everyone,

Only recently I got to learn about 'xterm-bracketed-paste' when all of a sudden CMD-V-ing had stopped working on my Mac, and while I found a solution that worked with my setup [0], I am still not 100% sure the solution I found is the correct one -- so here I am asking.

Question: is it expected that users create insert-mode mappings to support bracketed-paste?  Or, once enabled, proper-pasting should just work out of the box?  Because it looks like everything it's working fine when pasting in normal mode, but when in insert mode, the result is a mess (i.e. insert-mode mappings are executed, and autoindent screws indentation).

Example: say you had the following copied in the OS clipboard:

function foo() {
   while (true) {
     console.log('infinite!');
   }
}

And you started vim with: `vim -u NONE -c 'inoremap { {}'`; in normal mode, you press CMD-V and end up with the following buffer:

function foo() {
   while (true) {
     console.log('infinite!');
   }
}

~

Enter now insert mode, press CMD-V, and your buffer would look like the following (imaps and autoindent messed with the pasted content):

function foo() {
   while (true) {
     console.log('infinite!');
   }
}
function foo() {}
   while (true) {}
       console.log('infinite!');
         }
         }

I cannot reproduce the indentation issue. Besides, if I add -N to Vim's
options, I cannot reproduce the issue altogether. Is nocompatible set
in your Vim? I am using Vim 8.0.1750 on macOS 10.13.

Life.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Supporting xterm-bracketed-paste

Matteo Landi-2
Found the offending line in my .vimrc:

  inoremap <expr> <Esc>  pumvisible() ? "\<C-e>" : "\<Esc>"

Is this somehow breaking braketed paste? (i.e. swallowing the escape the terminal send at the beginning of a paste block)

Matteo

On Mon, May 7, 2018 at 11:21 PM, Matteo Landi <[hidden email]> wrote:
if I add -N to Vim's options, I cannot reproduce the issue altogether.

Ok, as Life pointed out earlier, pasting works fine with `vim -u NONE -N foo.js  -c 'inoremap { {} | set autoindent'`, which means the problem might be in the.vimrc or in one of the linked plugins.  Any hint on how to narrow down the search for the misconfigured setting?

Thanks,
Matteo

On Mon, May 7, 2018 at 7:36 AM, Matteo Landi <[hidden email]> wrote:
I cannot reproduce the indentation issue. Besides, if I add -N to Vim's

I just realized the vim command in my previous message did not include 'set autoindent': try with `vim -u NONE  -c 'inoremap { {} | set autoindent'`.

Is nocompatible set in your Vim? I am using Vim 8.0.1750 on macOS 10.13.

Yes.

:echo &compatible
0

Thanks,
Matteo

On Sun, May 6, 2018 at 10:37 PM, Lifepillar <[hidden email]> wrote:
On 06/05/2018 17:45, Matteo Landi wrote:
Hello everyone,

Only recently I got to learn about 'xterm-bracketed-paste' when all of a sudden CMD-V-ing had stopped working on my Mac, and while I found a solution that worked with my setup [0], I am still not 100% sure the solution I found is the correct one -- so here I am asking.

Question: is it expected that users create insert-mode mappings to support bracketed-paste?  Or, once enabled, proper-pasting should just work out of the box?  Because it looks like everything it's working fine when pasting in normal mode, but when in insert mode, the result is a mess (i.e. insert-mode mappings are executed, and autoindent screws indentation).

Example: say you had the following copied in the OS clipboard:

function foo() {
   while (true) {
     console.log('infinite!');
   }
}

And you started vim with: `vim -u NONE -c 'inoremap { {}'`; in normal mode, you press CMD-V and end up with the following buffer:

function foo() {
   while (true) {
     console.log('infinite!');
   }
}

~

Enter now insert mode, press CMD-V, and your buffer would look like the following (imaps and autoindent messed with the pasted content):

function foo() {
   while (true) {
     console.log('infinite!');
   }
}
function foo() {}
   while (true) {}
       console.log('infinite!');
         }
         }

I cannot reproduce the indentation issue. Besides, if I add -N to Vim's
options, I cannot reproduce the issue altogether. Is nocompatible set
in your Vim? I am using Vim 8.0.1750 on macOS 10.13.

Life.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Supporting xterm-bracketed-paste

Christian Brabandt

On Mi, 09 Mai 2018, Matteo Landi wrote:

> Found the offending line in my .vimrc:
>
>   inoremap <expr> <Esc>  pumvisible() ? "\<C-e>" : "\<Esc>"
>
> Is this somehow breaking braketed paste? (i.e. swallowing the escape the
> terminal send at the beginning of a paste block)

Very likely. It also breaks the various terminal request strings that
Vim requests when starting up. You might want to check, if this mapping  
works, if you only define it in a VimEnter autocommand.

Alternatively, I wouldn't recommend mapping ESC anyhow.

Best,
Christian
--
Läßt der Knecht die Arbeit liegen, kann er leicht 'n Arsch vollkriegen.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Supporting xterm-bracketed-paste

Matteo Landi-2
> You might want to check, if this mapping works, if you only define it in a VimEnter autocommand.

I tried that, but no luck.  Again, the only way to make it work is by including: https://github.com/ryanpcmcquen/fix-vim-pasting -- or with the following snippet

  if empty('&t_BE')
      inoremap <expr> <Esc>  pumvisible() ? "\<C-e>" : "\<Esc>"
  else
      augroup bracketed_paste
          au!
  
          function! XTermPasteBegin()
              set pastetoggle=<Esc>[201~
              set paste
              return ""
          endfunction
          au VimEnter * inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
  
          au VimEnter * inoremap <special> <expr> <Esc>  pumvisible() ? "\<C-e>" : "\<Esc>"
      augroup END
  endif

Which feels like cheating, as it seems like we are re-implementing support for braketed-paste, manually.  Anyway, at least now I think I understood why that plugin/snippet is required.

> Alternatively, I wouldn't recommend mapping ESC anyhow.

Yeah, that would work too ;-)

Thanks,
Matteo

On Wed, May 9, 2018 at 12:11 PM, Christian Brabandt <[hidden email]> wrote:

On Mi, 09 Mai 2018, Matteo Landi wrote:

> Found the offending line in my .vimrc:
>
>   inoremap <expr> <Esc>  pumvisible() ? "\<C-e>" : "\<Esc>"
>
> Is this somehow breaking braketed paste? (i.e. swallowing the escape the
> terminal send at the beginning of a paste block)

Very likely. It also breaks the various terminal request strings that
Vim requests when starting up. You might want to check, if this mapping 
works, if you only define it in a VimEnter autocommand.

Alternatively, I wouldn't recommend mapping ESC anyhow.

Best,
Christian
--
Läßt der Knecht die Arbeit liegen, kann er leicht 'n Arsch vollkriegen.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.