Two-way file comparison for Textadept.
Install this module by copying it into your ~/.textadept/modules/ directory or Textadept's modules/ directory, and then putting the following in your ~/.textadept/init.lua:
require('file_diff')
A sample workflow is this:
- Start comparing two files via the "Compare Files" submenu in the "Tools" menu.
- The caret is initially placed in the file on the left.
- Go to the next change via menu or key binding.
- Merge the change from the other buffer into the current one (right to left) via menu or key binding.
- Go to the next change via menu or key binding.
- Merge the change from the current buffer into the other one (left to right) via menu or key binding.
- Repeat as necessary.
Note: merging can be performed wherever the caret is placed when jumping between changes, even if one buffer has a change and the other does not (additions or deletions).
Windows, Linux, BSD | macOS | Terminal | Command |
---|---|---|---|
Tools | |||
F6 | F6 | F6 | Compare files... |
Shift+F6 | ⇧F6 | S-F6 | Compare the buffers in two split views |
Alt+Down | ⌥⇣ | M-Down | Goto next difference |
Alt+Up | ⌥⇡ | M-Up | Goto previous difference |
Alt+Left | ⌥⇠ | M-Left | Merge left |
Alt+Right | ⌥⇢ | M-Right | Merge right |
The indicator number for text added within lines.
The indicator number for text deleted within lines.
The marker for line additions.
The marker for line deletions.
The marker for line modifications.
The theme to use, either 'dark' or 'light'. This is not the theme used with Textadept. Depending on this setting, additions will be colored 'dark_green' or 'light_green', deletions will be colored 'dark_red' or 'light_red', and so on. The default value is auto-detected.
Returns a list that represents the differences between strings text1 and text2. Each consecutive pair of elements in the returned list represents a "diff". The first element is an integer: 0 for a deletion, 1 for an insertion, and 2 for equality. The second element is the associated diff text.
Parameters:
text1
: String to compare against.text2
: String to compare.
Usage:
diffs = diff(text1, text2) for i = 1, #diffs, 2 do print(diffs[i], diffs[i + 1]) end
Return:
- list of differences
Jumps to the next or previous difference between the two files depending on boolean next.
file_diff.start()
must have been called previously.
Parameters:
next
: Whether to go to the next or previous difference relative to the current line.
Merges a change from one buffer to another, depending on the change under the caret and the merge direction.
Parameters:
left
: Whether to merge from right to left or left to right.
Highlight differences between files file1 and file2, or the user-selected files.
Parameters:
file1
: Optional name of the older file. If-
, uses the current buffer. Ifnil
, the user is prompted for a file.file2
: Optional name of the newer file. If-
, uses the current buffer. Ifnil
, the user is prompted for a file.horizontal
: Optional flag specifying whether or not to split the view horizontally. The default value isfalse
, comparing the two files side-by-side.