gpt4 book ai didi

sublimetext3 - sublime中如何删除重复字符?

转载 作者:行者123 更新时间:2023-12-02 14:48:07 26 4
gpt4 key购买 nike

之前:

我是中国人来自中国,I am Chinese people from China

之后:

我是中国人来自,IamChinespolfr

如何在sublime中删除重复的字符?

最佳答案

ST 控制台的单行文字 ctrl+` :

import collections; content="".join(collections.OrderedDict.fromkeys(view.substr(sublime.Region(0, view.size())))); view.run_command("select_all"); view.run_command("insert", {"characters": content})

如果你想写一个插件,请按 Tools >>> New Plugin...并写:

import sublime
import sublime_plugin
from collections import OrderedDict


class RemoveDuplicateCharactersCommand(sublime_plugin.TextCommand):
def remove_chars(self, edit, region):
view = self.view
content = "".join(OrderedDict.fromkeys(view.substr(region)))
view.replace(edit, region, content)

def run(self, edit):
view = self.view
all_sel_empty = True
for sel in view.sel():
if sel.empty():
continue
all_sel_empty = False
self.remove_chars(edit, sel)
if all_sel_empty:
self.remove_chars(edit, sublime.Region(0, view.size()))

并在Keybindings - User中创建一个键绑定(bind):

{
"keys": ["ctrl+alt+shift+r"],
"command": "remove_duplicate_characters",
},

之后您只需选择一个文本并按 ctrl+alt+shift+r并且重复的字符将被删除。如果您没有选择,它将应用于整个 View 。

关于sublimetext3 - sublime中如何删除重复字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36884079/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com