Chapter 11 · Pro modulesPro 模块Pro 模組
File comparison and merge文件比较与合并檔案比較與合併
Pro
Starting a comparison
- Open the two files you want to compare.
- Use the comparison command to put the active document on one side and choose the other file for the second side.
- The window switches to a two-pane aligned view.
Algorithm
The diff uses Myers plus Patience on the line level. Options control whether whitespace-only changes are ignored and whether moved blocks are detected.
Highlight kinds
| Kind | Meaning |
|---|---|
| Added | Line exists only on the right. |
| Removed | Line exists only on the left. |
| Moved | Block appears in both files at different positions (when move detection is on). |
| Modified | Line pairs differ. |
| Inline | Within a modified line, the character runs that differ. |
All five have configurable colours in Preferences → Appearance → comparison colours.
Navigating differences
- Next and previous difference jump between hunks and keep both panes aligned.
- Swap left and right, or re-run the comparison after editing.
- Clearing the comparison returns to the normal editor.
Synchronised scrolling and wrapping
Scrolling one pane scrolls the other proportionally. Toggling word wrap during a comparison applies the same state to both panes, so the alignment does not drift.
Inline diff limit
Character-level highlighting is generated only when both files are 2,000 lines or fewer. Larger files keep whole-line highlighting, which keeps comparison responsive. This is a deliberate limit, not a rendering failure.
Progress and large inputs
Diff computation runs on a background thread with a progress indicator. Starting a comparison on two very large files is allowed, but expect the inline pass to be skipped.
Merge behaviour
Differences can be applied from one side to the other hunk by hunk, then saved as normal documents. There is no three-way merge and no conflict-marker workflow.
Pro
开始比较
- 打开要比较的两个文件。
- 使用比较命令,把当前文档放在一侧,再选择另一侧的文件。
- 窗口切换为两栏对齐视图。
算法
行级差异使用 Myers + Patience。选项可控制是否忽略仅空白差异、是否检测移动块。
高亮类型
| 类型 | 含义 |
|---|---|
| 新增 | 仅右侧存在的行。 |
| 删除 | 仅左侧存在的行。 |
| 移动 | 同一块内容在两侧位置不同(开启移动检测时)。 |
| 修改 | 成对但内容不同的行。 |
| 行内 | 修改行内部不一致的字符段。 |
五种颜色均可在偏好设置 → 外观 → 比较颜色中自定义。
差异导航
- 上一个 / 下一个差异在 hunk 之间跳转,并保持两栏对齐。
- 可交换左右文件,或在编辑后重新比较。
- 清除比较可回到普通编辑状态。
同步滚动与换行
滚动一侧时另一侧按比例联动。比较期间切换自动换行会同时作用于两栏,避免对齐位置漂移。
行内差异上限
仅当两侧文件都不超过 2,000 行时生成字符级高亮;更大的文件只保留整行高亮,以保证比较流畅。这是有意设定的上限,不是渲染失败。
进度与大文件
差异计算在后台线程执行并显示进度。两个超大文件也可以比较,但行内差异会被跳过。
合并行为
可以逐个 hunk 把差异从一侧应用到另一侧,然后按普通文档保存。不支持三方合并,也没有冲突标记工作流。
Pro
開始比較
- 開啟要比較的兩個檔案。
- 使用比較命令,把當前文件放在一側,再選擇另一側的檔案。
- 視窗切換為兩欄對齊檢視。
算法
行級差異使用 Myers + Patience。選項可控制是否忽略僅空白差異、是否檢測移動塊。
高亮類型
| 類型 | 含義 |
|---|---|
| 新增 | 僅右側存在的行。 |
| 刪除 | 僅左側存在的行。 |
| 移動 | 同一塊內容在兩側位置不同(開啓移動檢測時)。 |
| 修改 | 成對但內容不同的行。 |
| 行內 | 修改行內部不一致的字元段。 |
五種顏色均可在偏好設定 → 外觀 → 比較顏色中自定義。
差異導航
- 上一個 / 下一個差異在 hunk 之間跳轉,並保持兩欄對齊。
- 可交換左右檔案,或在編輯後重新比較。
- 清除比較可回到普通編輯狀態。
同步捲動與換行
捲動一側時另一側按比例聯動。比較期間切換自動換行會同時作用於兩欄,避免對齊位置漂移。
行內差異上限
僅當兩側檔案都不超過 2,000 行時生成字元級高亮;更大的檔案只保留整行高亮,以保證比較流暢。這是有意設定的上限,不是渲染失敗。
進度與大檔案
差異計算在後台執行緒執行並顯示進度。兩個超大檔案也可以比較,但行內差異會被跳過。
合併行為
可以逐個 hunk 把差異從一側應用到另一側,然後按普通文件儲存。不支援三方合併,也沒有衝突標記工作流。