2015/09/25

sublime RegReplace

關於 RegReplace 的使用

在研究去除 bbs 控制碼時,原本打算自己寫 macro ,爬文之後發現有更好的解法:使用 sublime 的 plugin

安裝基本上照著官網做沒問題

才怪,官網少了第三步驟

  1. Ensure Package Control is installed. Instructions are found here.
  2. In Sublime Text, press ctrl + shift + p (Win, Linux) or cmd + shift + p (OSX) to bring up the quick panel. It will show a list of installable plugins.
  3. 先輸入 install package
  4. Start typing RegReplace; when you see it, select it.
  5. Restart to be sure everything is loaded proper.
  6. Enjoy!

先寫 settings
{
     "replacements": {
     "remove_bbs_control_codes": {
          "find": "(\\[.*?m)",    //正規標示法必須用 () 包起來,必須用兩個 escape 表示 \
          "replace": "",
          "greedy": true,
          "case": false
          }
     }
}

再寫 commands

    {
        "caption": "Reg Replace: Remove BBS control codes",
        "command": "reg_replace",
        "args": {"replacements": ["remove_bbs_control_codes"]}
    }

最後再指定快速鍵

   {
    "keys": ["ctrl+shift+y"],
    "command": "reg_replace",
    "args": {"replacements": ["remove_bbs_control_codes"]}
  }

步驟有點冗長

有另外一個作法是,在存檔時觸發 regReplace ,參考官網文件的這個章節
Apply Regex Right Before File Save Event

沒有留言: