如何去除sublime中的重复字符?

how to remove duplicate characters in sublime?

之前:

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

之后:

我是中国人来自,IamChinespolfr

如何去除sublime中的重复字符?

  1. 打开Find菜单
  2. Select Replace...
  3. 确保 Regular expression 模式已启用
  4. Find What: 中,键入 (.)(.*?)
  5. Replace With: 中,键入 </code></li> <li>点击<code>Replace All
  6. 重复直到不再有 matches/duplicate 个字符

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 中创建一个键绑定:

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

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