中间button粘贴删除的文字在崇高3

(注意:这个问题不同于在Sublime Text 3中的中间button上粘贴光标 )

我在Linux上使用Sublime Text 3(但它也适用于Sublime Text 2)。

在emacs和vim中,可以突出显示一些文本(将其复制到剪贴板),删除文本,然后使用鼠标中键将其粘贴到其他位置。 这是我平常移动一些文本的工作stream程(select-> delete-> middleclick)。

然而,在崇高,它不会粘贴任何东西,即中间button粘贴function只适用于非删除文本,显然。 有谁知道如何使它与删除的文字呢?

Solutions Collecting From Web of "中间button粘贴删除的文字在崇高3"

我用这样的插件来了:

 import sublime, sublime_plugin import re class Mylistner(sublime_plugin.Eventlistner): def __init__(self): sublime_plugin.Eventlistner.__init__(self) self.deleted = '' self.mark_for_clear = '' self.clipboard_save = '' self.empty_matcher = re.compile('^\s+$') # Clear last deleted word if user made highlight of another one # Delete if you want to eg delete one word and highlight another to replace def on_selection_modified(self, view): selected_text = view.substr(view.sel()[0]) if self.mark_for_clear != '' and self.mark_for_clear != self.deleted: self.deleted = '' self.mark_for_clear = '' if len(selected_text) > 0 and not self.empty_matcher.match(selected_text): self.mark_for_clear = selected_text def on_text_command(self, view, name, args): # Save deleted word if command was deletion command if name in ['right_delete', 'left_delete']: self.deleted = view.substr(view.sel()[0]) #print("Deleted: %s " % self.deleted) # Propagate saved deleted word to clipboard and change command to # standard paste (we can only control standard paste clipboard) if name == "paste_selection_clipboard" and len(self.deleted) > 0: #print("Pasting:%s" % self.deleted) self.clipboard_save = sublime.get_clipboard() sublime.set_clipboard(self.deleted) # Comment line below to enable multiple middle-click pasting of deleted words: self.deleted = '' return("paste", 'HackedByAlkuzad') # If we are after paste_selection_clipboard command, return old clipboard def on_post_text_command(self, view, name, args): if name == 'paste' and len(self.clipboard_save) > 0 and args == 'HackedByAlkuzad': sublime.set_clipboard(self.clipboard_save) self.clipboard_save = '' 

这个插件会检测删除文件(right = delete,left = backspace),并将删除的内容复制到内存中。 然后,如果用户使用中键单击粘贴,则会将剪贴板替换为已删除的内容并粘贴。 粘贴后恢复保存的剪贴板。

我认为从删除副本应该工作在空的空间(ST没有没有复古的插入模式)。 要改变这种行为,你可以删除on_selection_modified函数来停止检查,但是突出显示新的单词不会将其复制到中间按钮剪贴板。

编辑:使用Linux xclip的系统范围剪贴板的版本(从pyperclip获取)

 import sublime, sublime_plugin import re from subprocess import Popen, PIPE, check_call, CalledProcessError class DeletedToClipboard(sublime_plugin.Eventlistner): empty_matcher = re.compile('^\s*$') def __init__(self): sublime_plugin.Eventlistner.__init__(self) try: check_call(['which','xclip']) except CalledProcessError: sublime.error_message("You have to have xclip installed to use DeletedToClipboard") @classmethod def _is_empty(cls, text): return len(text) <= 0 or cls.empty_matcher.match(text) # Thanks pyperclip :) @classmethod def _copy_to_system_clipboard(cls, text): # try secondary if not working p = Popen(['xclip', '-selection', 'primary'], stdin=PIPE) try: p.communicate(input=bytes(text, 'utf-8')) except Exception as e: print("Error on paste to clipboard, is xclip installed ? \n{}".format(e)) def on_text_command(self, view, name, args): # Save deleted word if command was deletion command and selected text was not empty if name in ['right_delete', 'left_delete']: deleted = [] for region in view.sel(): text = view.substr(region) if not DeletedToClipboard._is_empty(text): deleted.append(text) if deleted != []: self._copy_to_system_clipboard("\n".join(deleted))