Sublime Forum

Cannot Paste Code?

#1

I just tried to copy/paste lines 1-7 from php exit foreach Code Example (codegrepper.com) and it pasted fine into notepad but gives me this in Sublime, even after copy/paste from notepad… anyone have the same or know what I can do?

1 Like

#2

0xa0 is a non-breaking space. Most things won’t filter that out, but it’s likely to break various languages. I suggest simply replacing all of them with a regular space.

1 Like

#3

Thanks. Thought it was very odd and didn’t know if Sublime had a paste as plain text that would be beneficial or quicker than having to replace. Works and goes quick with Alt+F3 to select all, but wasn’t sure if there was a better way. Appreciate the feedback.

0 Likes

#4

Sublime Text can only paste plain text. Non breaking spaces aren’t formatting, they’re entirely separate characters that have their special use cases.

0 Likes

#5

You can use a simple plugin as a workaround, which assumes you never want to paste <0xa0> under any circumstances.

import sublime
import sublime_plugin


class PasteSanitization(sublime_plugin.EventListener):
    def on_text_command(self, view: sublime.View, name: str, args: dict = {}) -> None:
        if name in ("paste", "paste_and_indent"):
            sublime.set_clipboard(sublime.get_clipboard().replace("\xa0", " "))

        return None
0 Likes