2016-04-27 32 views

回答

0
  1. 打開Find菜單
  2. 選擇Replace...
  3. 確保Regular expression模式已啓用
  4. Find What:,類型(.)(.*?)\1
  5. Replace With:,類型$1$2
  6. 點擊Replace All
  7. 重複直到有沒有更多的匹配/重複的字符
2

A中的一個襯爲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和重複的字符將被刪除。如果您沒有選擇,它將應用於整個視圖。

+0

不錯的解決方案,比我的基於非插件/ python的答案少重複的手動工作:) –