之前:
我是中国人来自中国,I am Chinese people from China
之后:
我是中国人来自,IamChinespolfr
如何删除sublime中的重复字符?
答案 0 :(得分:4)
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",
},
之后您只需选择一个文字并按ctrl+alt+shift+r
即可删除重复的字符。如果您没有选择,它将应用于整个视图。
答案 1 :(得分:1)
Find
菜单Replace...
Regular expression
模式Find What:
中,输入(.)(.*?)\1
Replace With:
中,输入$1$2
Replace All