I am running VirtualBox 5.0.5 on a 64-bit Windows 7 host with guest 64-bit Debian 7. The clipboard is bidirectional.
When I copy text from Sublime Text 2 on the guest and paste it into any editor on the host, an extra newline is added to every line. It does not seem to occur when copying from other sources. This would somehow make sense if it were adding carriage returns for Windows' sake, i.e. changing "\n" to "\r\n", but it's not, it's changing "\n" to "\n\n".
I get around this by pasting the text into Notepad++ then using search-and-replace to replace every "\n\n" with "\n", but I've finally decided I'm tired of doing this.
Is there something I can do about this to avoid the extra newlines?
Update
I wrote a small Windows program to examine the Windows clipboard, and it looks like the clipboard is actually replacing each individual line ending with "\r\r\n", no matter what default_line_ending
is set to, and no matter which line endings the source document actually contains. Most Windows programs simply interpret "\r\r\n" as two lines and put two of whatever format is expected; I have Notepad++ configured to use Unix line endings by default, so it was converting "\r\r\n" to "\n\n".
Update 1.5
Example case: Copying this from Sublime Text 2 in the guest (with "\n" as line ending)
cat
on
mat
becomes in the Windows clipboard (with hexadecimal and decimal interpretation):
c 0x63 99
a 0x61 97
t 0x74 116
? 0x0D 13
? 0x0D 13
? 0x0A 10
o 0x6F 111
n 0x6E 110
? 0x0D 13
? 0x0D 13
? 0x0A 10
m 0x6D 109
a 0x61 97
t 0x74 116
Update 2
I wrote a Sublime Text 2 plug-in to do a similar test. Copying this text in the guest
cat
on
mat
puts into the guest clipboard (with decimal interpretation):
c 99
a 97
t 116
? 10
o 111
n 110
? 10
m 109
a 97
t 116
So according to Sublime Text 2, nothing is amiss, yet when Windows accesses the clipboard containing text from Sublime Text 2, the messed up end lines are retrieved. This doesn't happen when I copy text from other sources on the host or guest.
Another phenomenon is that if I have text highlighted anywhere in the guest, if I press Ctrl+C anywhere in the guest or host, the guest's highlight goes away. Could this be related to the main issue? Or perhaps both of these are a symptoms of an underlying issue?
Update 3
It looks like Sublime Text 2 is always sending "\n" to the clipboard (before the jumble), even when I have default_line_ending
set to windows
and I copy from a text file that has "\r\n" for line endings. I also noticed that in the Windows-style text file, when I highlight text, each line ending only counts for 1 character instead of 2 when Sublime Text 2 reports "x lines, y characters selected." I would guess Sublime Text 2 has some aggressive line ending management and it's not communicating properly with the clipboard.
I don't know if this is of any use, but if I query the Windows Clipboard for its formats, it reports
1 TEXT
7 OEMTEXT
13 UNICODETEXT
16 LOCALE
I've created an all-new virtual machine guest running Debian 9. I installed Sublime Text 2 then Sublime Text 3 on it and configured them as close as I can to Sublime Text 2 on my old guest.
Copying text from Sublime Text 3 on the new guest to the Windows 7 host does not have this issue, while copying text from Sublime Text 2 on the same new guest still does. I'm chalking this up to a bug between Sublime Text 2 and Windows which was resolved somewhere in Sublime Text 3's revisions.
Solution: Upgrade to Sublime Text 3.