You would need a plugin for that on systems that aren’t Linux; as far as I know there is no such package for Windows/MacOS that would provide this.
The following is an example plugin that would do this, though note that it is a fairly simple sample all things considered. It watches for ANY selection change (be it keyboard or mouse related) and captures the selected text, which the associated command will insert verbatim.
Note:
- The capture of the selected text will only happen if there is exactly 1 selection (cursor) and that selection is not empty
- The
fake_clipboard_paste
command disables itself and will do nothing if there is no text in the fake clipboard yet (generally only after a Sublime start) OR there is more than one selection (cursor) OR there is selected text (i.e. if you want to replace selected text with the new text, press backspace
after you select the text).
The mousemap entry you would want for this would be:
// Note: this overrides the default ability to column select
// with the middle mouse button.
{ "button": "button3", "command": "fake_clipboard_paste" }
If you’re not sure how to install a plugin, see this video
import sublime
import sublime_plugin
import functools
# Storage for the "fake clipboard"; only tracks a single string at a time
_fake_clipboard = ''
class FakeClipboardEventListener(sublime_plugin.EventListener):
"""
Simple listener that puts the currently selected text FROM THE FIRST
SELECTION ONLY into a "fake clipboard" whenever the selection changes for
any reason and the first selection is not empty.
This means that selecting text with the mouse or keyboard, or any command
that causes text to be selected will update the fake clipboard.
"""
pending = 0
def on_selection_modified_async(self, view):
self.pending += 1
sublime.set_timeout_async(functools.partial(self.update, view), 100)
def update(self, view):
self.pending -= 1
if self.pending != 0:
return
global _fake_clipboard
# If the view has at least one cursor in it, AND the area of the first
# selection is non-zero (i.e. it is not just a cursor), pull out the
# text of the selection and put it into the fake clipboard.
if view.sel() and len(view.sel()[0]):
_fake_clipboard = text = view.substr(view.sel()[0])
class FakeClipboardPasteCommand(sublime_plugin.TextCommand):
"""
When triggered, the text from the fake clipboard is inserted at the
position of the first cursor.
The command disables itself if there is more than one selection, any text
is currently selected, or the fake clipboard is empty.
"""
def run(self, edit):
self.view.insert(edit, self.view.sel()[0].b, _fake_clipboard)
def is_enabled(self):
# Disable the command when the clipboard is empty, there is more than
# one selection, or the first selection is not empty.
return (
_fake_clipboard != '' and
len(self.view.sel()) == 1 and
len(self.view.sel()[0]) == 0)