Sublime Forum

How I work with files that contain C0 and C1 chars?

#1

I want for example to be able to copy a text that contains NUL or CR or BEL and paste elsewhere.

Sublimetext already displays them, but seemly you can’t copy or insert them at all, only erase them.

0 Likes

#2

As this shows, it “mostly” works; you can copy and paste some such characters, just not a NUL or CR byte (although my test was by no means extensive so the list may be longer).

If you watch the status bar, it’s saying that it is copying 7 characters every time I copy a line, but when pasting the line with the CR or NUL byte, that byte doesn’t paste.

The CR is not pasted because it’s treated as a CR character should be (if there is more text after it, it shows up on the next line). Similarly, C based languages terminate their strings with a NUL byte, so it’s entirely believable that such a string paste would stop at the NUL byte because it thinks that it’s reached the end of the string.

On the one hand that could be seen as a defect, but on the other hand as a text editor I find it suitable that it works this way since it’s meant for editing text and not what is (by some standard) a binary file. In fact in order to open the file I had to get Sublime to reopen it as UTF-8 since it assumed Hexadecimal encoding by default.

For the curious, I created the file originally using vi, but it is possible to insert such control characters in Sublime:

view.run_command ("insert", {"characters": "\x0d"})

Although it’s not possible to insert a NUL byte in this manner (presumably due to it thinking that the string is terminating in this case). There is no key binding for something like this by default, but one could be added if desired.

1 Like

#3

There is an issue regarding the null byte in clipboard on the issue tracker.

2 Likes

#4

I talked with SText author on IRC, seemly it is because of OS issues.

SText send the NUL bytes to clipboard, but then the OS clips the text.

To allow NUL copy/pasting would require some custom copy-paste code (for example something that transforms NULs into something else before sending to clipboard, and then transforms it back).

0 Likes