Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 2
    Wow - It's really rare when I see a new user provide a correct and useful answer to an old question! Congratulations, and welcome to Stack Overflow! One small suggestion - Provide some detail on why this works, so people better understand the mechanics and can adjust it to other uses. I'm going to make a small edit to it to add this info. Commented Jul 9, 2021 at 15:11
  • 1
    For those wondering, pasting into WSL Vim from clipboard can still be done by right-clicking while in insert mode.
    – mbomb007
    Commented Jan 7, 2022 at 16:32
  • Command equivalent for pasting is powershell.exe Get-Clipboard. Caveats due to UNIX and Windows convention mismatch: the output of powershell.exe Get-Clipboard will have carriage returns on each line, and the UNIX norm of having a trailing newline at the end of the last line is interpreted by the Windows clipboard as an extra empty line at the end.
    – mtraceur
    Commented Feb 15, 2023 at 5:08
  • So a fuller solution is probably perl -pe 'chomp if eof' | clip.exe for copy (to chomp off one trailing newline if there is one), and powershell.exe Get-Clipboard | sed 's/\r$//' for paste (to delete the spurious carriage returns at the end of each line). This is the closest we get to a translation between UNIX and Windows text semantics. (Sadly, the trailing newline workaround means there's an ambiguity/collision on the round trip - if you intentionally send data with no trailing newline to the Windows clipboard, you'll get back data with a trailing newline.)
    – mtraceur
    Commented Feb 15, 2023 at 5:34
  • this tip actually works! even though it defeats the purpose of efficiency. But obviously it only applies to local WSL vim. If you e.g. ssh somehwere then it seems you are out of luck without really awkward xserver piping. Easier to mouse select in terminal window but don't forget to disable line numbers before...
    – rogerovo
    Commented Mar 24, 2023 at 21:14