Hi Tony,

I was actually writing a plugin for this, and since I could change its
implementation I ended up with something like (note the call to
substitute() right after system()):

function! s:paste(...) " {{{
  let l:after = get(a:, 1, 1)
  let reg_save = @@

  let @@ = system(g:cb_paste_prg)
  " XXX pastin on Windows somehow leaves trailing ^M
  " gotta figure out a better way to fix this, but
  " for now, this will do!
  let @@ = substitute(@@, "\r\n", "\n", "g")
  setlocal paste
  if l:after
    exe 'normal p'
  else
    exe 'normal P'
  endif
  setlocal nopaste

  let @@ = reg_save
endfunction " }}}

I will leave this here for a little while, and then I will probably
cross-post it on vim_dev.

Thanks again for the help.

On Mon, Nov 18, 2019 at 10:43 PM Tony Mechelynck <
[email protected]> wrote:

> On Mon, Nov 18, 2019 at 4:11 PM Matteo Landi <[email protected]>
> wrote:
> >
> > Hi Tony,
> >
> > The thing is, :read! appears to be stripping ^M already, irrespective of
> the use of ++opts:
> >
> >   :read !powershell.exe Get-Clipboard
> >   :read ++ff=unix !powershell.exe Get-Clipboard
> >   :read ++ff=dos !powershell.exe Get-Clipboard
> >
> > To be honest, I'd expect the second one, where we specify ++ff=unix, to
> leave trailing ^M, but somehow that's not happening, and for your reference
> (after I vim -u NONE):
> >
> >   :verbose set ff
> >
> > Returns 'fileformat=unix'
> >
> >   :verbose set ffs
> >
> > Returns 'fileformats=unix,dos'
> >
> > So am I correct if I say that there is something "weird" going on with
> system()?  I also found the following at the end of system()'s help page,
> but somehow the experienced behavior is not the documented one:
> >
> >   To make the result more system-independent, the shell output
> >   is filtered to replace <CR> with <NL> for Macintosh, and
> >   <CR><NL> with <NL> for DOS-like systems.
> >
> > I even tried to give systemlist() a go, but each entry of the array
> still has that trailing ^M, so it really seems like Vim cannot properly
> guess the fileformat from the command output.
> >
> > I am really in the dark here.
>
> So am I.
>
> As a last resort, the following Normal-mode mapping will remove (after
> the fact) all ^M characters found at he end of a line:
>
> :map <F5> :%s/<Ctrl-M>$//<CR>
>
> Of course, you can replace <F5> by something else (if for instance
> your Normal-mode F5 key is already mapped).
>
> Meaning of the {rhs}:
>         :       start an ex-command
>         %       or 1,$ : from top to bottom of the file
>         s       :s[ubstitute] (search and replace)
>         /       replace what
>         <Ctrl-M>  (typed as such: less-than, C, etc.) : ^M (carriage
> return)
>         $       at end-of-line
>         /       replace by what
>         (nothing)   replace by nothing
>         /       end of replace-what text
>         (nothing)   no flags: replace once (at most) per line (N.B.
> there can be only one end-of-line per line)
>         <CR>    end of ex-command
>
> Best regards,
> Tony.
>
> --
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vim_use/CAJkCKXsaTWz2Mw-8nKe5H05_2WFG_iPNnEtMa1bCQ3aN0Ja-7g%40mail.gmail.com
> .
>

-- 
-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/CAKpQHWbLxLLvgQhRBX1b5Lg8xZZYWKAM-rJa4aw3Ofvyhkaqug%40mail.gmail.com.

Reply via email to