Skip to content

Latest commit

 

History

201 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

PCode Merge (pk)

PCode Merge is a fast, keyboard-centric, vim-inspired patch merging and conflict resolution tool built with Rust and egui. It is designed to streamline the workflow of applying patches, reviewing diffs, and managing local file edits—especially in AI-assisted coding workflows where patches are generated by LLMs (like Aider) or standard git diff/unified diff formats.

rustconcat_patch_merge.mp4

✨ Features

  • Multi-Format Patch Parsing: Automatically detects and parses Aider-style search/replace blocks, standard Git/Unified diffs, and raw pastes.
  • Vim-like Modal Editing: Navigate and edit files seamlessly using familiar Vim-style keybindings (Normal, Insert, Visual modes).
  • Smart Auto-Matching: Utilizes LCS-based diffing to automatically find the best location in your file to apply a patch.
  • Manual Anchors (ma, mA): Force-apply patches to specific lines or ranges using manual anchors when auto-matching fails.
  • Git Integration: View line-by-line Git status, grouped Git hunks, and overall repo status directly in the UI.
  • Repository Management: Register and sync multiple local repositories via a background daemon.
  • Format on Save: Automatically format files using rustfmt or custom formatting commands upon saving.

🚀 Getting Started

Prerequisites

  • Rust and Cargo installed.
  • git2 system libraries (usually requires libgit2 and libssl-dev on Linux).

Building

cargo build --release

Running

You can run the tool directly, optionally passing a patch file:

# Start with an empty workspace
cargo run --release

# Start by loading a specific patch file
cargo run --release -- path/to/your/patch.md

⌨️ Keyboard Shortcuts

PCode Merge is designed to keep your hands on the keyboard. Here are the core bindings:

Global & Navigation

Key Action
L / Shift+L Next / Previous hunk
Alt + = / Alt + - Next / Previous file (if multiple in patch)
F1 / F4 / F3 Toggle Git Status / Git Diff / Debug panels
? Toggle Help overlay
Alt + W Save current file to disk
Alt + Q Quit application
Esc Cancel current action / Clear marks / Exit insert mode

File Panel (Right Side)

Key Action
Arrow Keys / hjkl Move cursor
Space Set mark a (ma) at cursor line
m + [letter] Set a custom marker
A Apply current hunk at auto-matched location
+ / - Shrink/Expand the auto-match range or anchor a range
/ Search forward in file
n / N Next / Previous search match
v Toggle Visual mode for block selection

Editing (Vim-style)

Key Action
i / I Enter Insert mode (at cursor / start of line / append)
o / O Open new line below/above and enter Insert mode
dd Delete current line
daf Delete function block around cursor
u Undo last edit
yy Yank (copy) current line
p / P Paste yanked line below / above
Esc Return to Normal mode

🛠 Workflow Guide

  1. Load a Patch: Click 📋 Paste Patch to load from clipboard, or 📝 Paste Manually to paste text directly. You can also launch the app with a file path argument.
  2. Set Target File: If the patch doesn't specify a filename, enter the target file path in the Target File input box on the left panel.
  3. Review the Hunk: Use L/Shift+L to navigate between hunks. The right panel will highlight the best auto-match location in the file.
  4. Apply the Hunk:
    • Press A to apply at the auto-matched location.
    • If the auto-match is wrong, move your cursor to the correct starting line, press Space (to set ma), then press A.
    • To apply a custom range, set ma at the start, move to the end line, press mA (or use the +/- keys to expand the range), then apply.
  5. Save: Press Alt + W to write the changes to disk. If Format on Save is enabled, it will run your formatter automatically.

⚙ Configuration

Settings are automatically saved and loaded from a config file. You can modify these via the ⚙ Config tab in the UI:

  • Format on Save: Toggle automatic formatting.
  • Format Command: The command to run for formatting (e.g., rustfmt, rustfmt --edition 2021, cargo fmt --).

About

patch-merge

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages