Chapter 12 · Pro modulesPro 模块Pro 模組
Macros宏巨集
Pro
Recording
- Put the caret where the macro should start.
- Start recording from the toolbar or the macro menu.
- Perform the edits you want to repeat.
- Stop recording. The macro is now available for playback.
Recording captures keystrokes and editing commands against the current document. A red indicator in the status area shows that recording is active.
Playback
| Mode | Use |
|---|---|
| Play once | Repeat the recorded steps at the caret. |
| Play N times | Repeat a fixed number of iterations. |
| Play to end of file | Apply repeatedly until the caret reaches the end. |
Shortcuts
Record, stop and play have default shortcuts — record is ⌥⇧⌘R, play is ⌥⇧⌘P in the shipped defaults. All three can be rebound in Macro → Manage Macros → Shortcuts.
Saving
Named macros are stored with the app's data and survive relaunches. They are scoped to the application, not to a document type, so a macro recorded for SQL text can be replayed anywhere — the recorder does not know what the text means.
Limits
- No conditionals, loops or variables. This is a keystroke recorder, not a scripting runtime.
- Macros replay literally; if the surrounding text changed, the result will differ.
- Undo treats a macro playback as ordinary edits, so
⌘Zcan roll it back step by step.
When a macro is the wrong tool
For repeated multi-file transformations, project-level replace with a regular expression is safer and reversible in one step. Use macros for repetitive caret-level work such as reformatting a column of values.
Pro
录制
- 把光标放到宏应该开始的位置。
- 从工具栏或宏菜单开始录制。
- 执行你想重复的编辑操作。
- 停止录制,宏即可用于播放。
录制会捕获针对当前文档的按键与编辑命令。状态区域出现红色指示表示正在录制。
播放
| 模式 | 用途 |
|---|---|
| 播放一次 | 在光标处重复录制的步骤。 |
| 播放多次 | 重复固定次数。 |
| 播放到文件末尾 | 反复执行直到光标到达末尾。 |
快捷键
录制、停止与播放都有默认快捷键——出厂默认为录制 ⌥⇧⌘R、播放 ⌥⇧⌘P。三者都可以在《宏 → 管理宏 → Shortcuts》中重新绑定。
保存
命名宏随应用数据保存,重启后仍在。宏是应用级而不是文档类型级的:为 SQL 文本录制的宏也能在别处播放,因为录制器并不理解文本含义。
限制
- 没有条件分支、循环或变量。它是按键录制器,不是脚本运行时。
- 播放是逐字重放;上下文一变,结果就会不同。
- 撤销把宏播放视为普通编辑,
⌘Z可以逐步回滚。
什么时候不该用宏
跨多文件的重复变换,用项目级正则替换更安全,也能一步撤销。宏更适合光标级的重复劳动,比如整理一列数值。
Pro
錄制
- 把游標放到巨集應該開始的位置。
- 從工具列或巨集選單開始錄制。
- 執行你想重復的編輯操作。
- 停止錄制,巨集即可用於播放。
錄制會捕獲針對當前文件的按鍵與編輯命令。狀態區域出現紅色指示表示正在錄制。
播放
| 模式 | 用途 |
|---|---|
| 播放一次 | 在游標處重復錄制的步驟。 |
| 播放多次 | 重復固定次數。 |
| 播放到檔案末尾 | 反復執行直到游標到達末尾。 |
快速鍵
錄制、停止與播放都有預設快速鍵——出廠預設為錄制 ⌥⇧⌘R、播放 ⌥⇧⌘P。三者都可以在《巨集 → 管理巨集 → Shortcuts》中重新綁定。
儲存
命名巨集隨應用資料儲存,重啓後仍在。巨集是應用級而不是文件類型級的:為 SQL 文字錄制的巨集也能在別處播放,因為錄制器並不理解文字含義。
限制
- 沒有條件分支、循環或變數。它是按鍵錄制器,不是腳本執行時。
- 播放是逐字重放;上下文一變,結果就會不同。
- 復原把巨集播放視為普通編輯,
⌘Z可以逐步回滾。
什麼時候不該用巨集
跨多檔案的重復變換,用專案級正則取代更安全,也能一步復原。巨集更適合游標級的重復勞動,比如整理一列數值。