linux如何卸载sublime,linux – 中间按钮粘贴Sublime 3中删除的文本

这篇博客介绍了如何在SublimeText3(也适用于SublimeText2)上模拟Emacs和Vim的中键粘贴功能,即使文本已被删除。作者提供了一个插件,该插件监听文本命令,当检测到删除操作时,将删除的文本保存到剪贴板,并在使用中键粘贴时替换原有剪贴板内容。这样可以实现在SublimeText中方便地移动和粘贴已删除的文本。
摘要由CSDN通过智能技术生成

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

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

然而,在Sublime上,它没有粘贴任何内容,即中间按钮粘贴功能仅适用于未删除的文本.有谁知道如何使它与删除的文本一起使用?

解决方法:

我带来了这样的插件:

import sublime, sublime_plugin

import re

class MyListener(sublime_plugin.EventListener):

def __init__(self):

sublime_plugin.EventListener.__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 e.g 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 = ''

此插件将检测删除comamnd(right = delete,left = backspace)并将已删除的内容复制到内存.然后,如果用户使用中间点击粘贴,它将替换具有已删除内容的剪贴板并粘贴它.粘贴后,它将恢复保存的剪贴板.

我假设删除的副本应该在空白空间上工作(ST没有没有Vintage的插入模式).要更改该行为,您可以删除on_selection_modified函数以停止检查该行为,但突出显示新单词不会将其复制到中键剪贴板.

编辑:

使用Linux xclip的系统范围剪贴板版本(取自pyperclip)

import sublime, sublime_plugin

import re

from subprocess import Popen, PIPE, check_call, CalledProcessError

class DeletedToClipboard(sublime_plugin.EventListener):

empty_matcher = re.compile('^\s*$')

def __init__(self):

sublime_plugin.EventListener.__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))

标签:linux,sublimetext2,sublimetext3

来源: https://codeday.me/bug/20190702/1359171.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值