[sublime]sql function模式

參考網址: Create a Regex Macro in Sublime

sport.sql.php 誀個檔案中放著sql建立資料表的語法,因為有許多資料表,要找到想要的資料表常常得翻來翻去,著實麻煩。
想說如果有個類似UltraEdit的function列表就方便找尋了,於是試著做做看。

#function aa_game_date {
#
# 資料表格式: `game_date`
#

DROP TABLE IF EXISTS game_date;
CREATE TABLE game_date (
  game_date_id tinyint(4) NOT NULL auto_increment,
  #主索引鍵
  
  game_date_str char(4) NOT NULL default '0',
  #比賽日期
  
  PRIMARY KEY  (game_date_id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8mb4  ;

#
# 列出以下資料庫的數據: `game_date`
#

INSERT INTO game_date VALUES (1, '0105');
INSERT INTO game_date VALUES (2, '0106');
INSERT INTO game_date VALUES (3, '0107');
INSERT INTO game_date VALUES (4, '0108');
#INSERT INTO game_date VALUES (5, '0205');
#} 


一開始糸嘗試用macro來做,發現macro無法記錄find 及 replace。
首先安裝symlist這個外掛,再來安裝regReplace外掛

JSON file with Find and Replace pairs

Go to the top menu Preferences/Package Settings/RegReplace/Rules-User.

{
    "format": "3.0",
    "replacements": {
        // function 變成function模式
        "func_start": {
            "find": "^#function",
            "replace": "function",
            "greedy": true
        },
        "func_end": {
            "find": "^#}",
            "replace": "}",
            "greedy": true
        },
        "func_top": {
            "find": "^#####top",
            "replace": "<?php",
            "greedy": true
        },
        "func_bottom": {
            "find": "^#####bottom",
            "replace": "?>",
            "greedy": true
        },
        // unfunction 變成註解模式
        "unfunc_start": {
            "find": "^function",
            "replace": "#function",
            "greedy": true
        },
        "unfunc_end": {
            "find": "^}",
            "replace": "#}",
            "greedy": true
        },
        "unfunc_top": {
            "find": "^<\\?php",
            "replace": "#####top",
            "greedy": true
        },
        "unfunc_bottom": {
            "find": "^\\?>",
            "replace": "#####bottom",
            "greedy": true
        }
    }
}
問號得加兩條\

JSON file with the Macro command

Go to the top menu Preferences/Package Settings/RegReplace/Rules-User.

[
  {
 	"caption": "RegReplace: function",
    "command": "reg_replace",
    "args": {"replacements": ["func_start","func_end","func_top","func_bottom"]}
  },
  {
 	"caption": "RegReplace: unfunction",
    "command": "reg_replace",
    "args": {"replacements": ["unfunc_start","unfunc_end","unfunc_top","unfunc_bottom"]}
  }
]

建立快捷鍵

Preferences/Key Buiding/user

[
	{
        "keys": ["ctrl+alt+f"],
        "command": "reg_replace",
        "args": {"replacements": ["func_start","func_end","func_top","func_bottom"]}
    },

	{
        "keys": ["ctrl+alt+u"],
        "command": "reg_replace",
        "args": {"replacements": ["unfunc_start","unfunc_end","unfunc_top","unfunc_bottom"]}
    }

]

 

原來不用這麼麻煩,outline外掛原本就內建sql模式,把語言改成sql,它就會自動抓'CREATE TABLE' 當大綱。
https://github.com/warmdev/SublimeOutline/issues/22
用ctrl+shift+p叫出Command Palette
輸入outline可以找到
Outline :Toggle Sort  切換list排序方式
Browse Mode:Outline(Left)
Browse Mode:Outline(Right)  list表放在右邊

本篇發表於 程式設計, 軟體使用。將永久鏈結加入書籤。