There are lots of quirks with WSL terminal, but using cross Vim copy/paste is top annoyance in my book. Nothing I tried as of April 2018 worked for pasting into Vim or other areas (using normal saneness) so, let's try to bypass the issue, and others related like buffer, for now. This is not a direct WSL solution, rather a workaround using a better terminal + SSH until MS provides a fix.
Putty, or it's extended fork Kitty, offer a more robust terminal compared to WSL. We can connect to the WSL (or any of your other servers) using SSH via localhost, using a custom port, and get a fuller featured terminal, including almost all Vim capabilities for bi-directional, or native pasting, scroll, etc. [You may need to tweak Vim conf to trigger all capabilities].
Putty/Kitty require an SSH server available in WSL, on a custom localhost port. If you haven't set up a localhost SSH server on your WSL already, here's a quick overview of how:
Step 1) Open the Ubuntu WSL terminal, do a sudo su
to auth as root, run vim /etc/ssh/sshd_config
to open SSH server conf.
Step 2) Look for "Port" near the first handful of lines. It may be set to 22. We need to set a custom port for our WSL SSH that doesn't collide. Hit i
to edit. Let's use port 9977 for example.
Step 3) If you're a dev, or otherwise don't need to bother with keys for your localhost WSL SSH, look for password authentication. You can set PasswordAuthentication yes
. Else, keys and higher security, or public access through firewall(s) on WSL, are beyond the scope of this answer.
Step 4) When done editing, hit esc to exit edit mode, then save+quit the file :wq
. Restart ssh service using service ssh restart
. Leave WSL open at this point as a master console.
Step 5) Create a new Putty/Kitty session, connect to localhost, using your custom port (9977 in our example). Log in with your WSL credentials, sudo su
if you require root. You should now have a much more robust shell available. Repeat or screen
as many views as you need.
I know it's not a direct answer, but at least it's a solution for now :)
If you're running Win10 pre-1709, then WSL is beta software obtained through the developer channel. Since then, the official release is Ubuntu (or OpenSUSE) available through Linux on Windows from MS Store. Despite your clarification, it's not clear which you're running. That said, I've found that the standard
cmd
terminal clip-board handling seems to work on both. – AFH – 2018-02-02T16:57:45.283No, this is most recent...non beta..from the store. I just installed it 3 days ago. I can't get vim to use the clipboard (rather it be windows or linux ...not sure which would be used in the unique WSL case). – dman – 2018-02-02T16:59:50.887
1It works for me in 1709: I have configured the bash terminal for Quick Edit mode and I use click and drag to select, right-click to copy selection and again to paste. – AFH – 2018-02-02T17:11:58.430
@AFH just to confirm, you are able to yank contents in vim using the vim yank command(ie:
yy
), have the yanked contents go to the clipboard, and paste from the clipboard using vim's paste (iepp
) in a separate vim session? – dman – 2018-02-04T03:55:19.817That seems to work: I typed
5yy
to copy 5 lines, restartedvim
, andp
pasted the 5 lines. – AFH – 2018-02-04T12:09:12.820@AFH I have that behavior also. But it's a different behavior if you have two separate vim sessions at the same time and you try to go back and forth with the pasting. – dman – 2018-02-07T18:17:54.530
Do you mean in separate
bash
windows? I'm not surprised if this is the case, as the two sessions would likely be independent of each other. But using Windows copy and paste will work between them. – AFH – 2018-02-07T21:15:11.1831@AFH yep... I used to be able to do this with two separate cygwin sessions using the windows clipboard registers. Any ideas on how to do it in WSL? – dman – 2018-02-07T22:42:51.783
Same way, as per my second comment. The paste can be done in any window, terminal-based or otherwise. – AFH – 2018-02-07T23:13:24.477
1
perhaps this does it? https://vi.stackexchange.com/q/15182/71
– Christian Brabandt – 2018-03-13T16:00:16.950To take this to a more general level, I think the gist of this would be "paste into vim from windows clipboard", not the reverse. Like if I were to copy a snippet for a config in windows browser, then try to paste that snippet into WSL term with vim open, nothing seems to work. – dhaupin – 2018-04-10T23:49:29.220