vimtabdiff/README.md

104 lines
3.6 KiB
Markdown
Raw Permalink Normal View History

2022-12-10 19:40:11 -05:00
Do you use `git difftool` to review changes before making a commit? The problem with that is that you get to see the diff of one file at a time. You can't easily stop it after few files and you can't go back to a previous file. `vimtabdiff.py` loads all the files with diffs, one in each vim tab page. You can move around any file and edit the diffs easily.
# Install
```bash
2022-12-10 19:40:11 -05:00
mkdir -p ~/bin
# for python version >= 3.10
curl -o ~/bin/vimtabdiff.py "https://raw.githubusercontent.com/balki/vimtabdiff/master/vimtabdiff.py"
# for python version < 3.10
2023-03-06 11:04:28 -05:00
curl -o ~/bin/vimtabdiff.py "https://raw.githubusercontent.com/balki/vimtabdiff/br-py38/vimtabdiff.py"
2022-12-10 19:40:11 -05:00
chmod +x ~/bin/vimtabdiff.py
```
2022-12-10 19:40:11 -05:00
2022-12-10 19:48:02 -05:00
You may need to add `~/bin` to your PATH variable if not already done. See [here](https://wiki.archlinux.org/title/Environment_variables#Per_user) for help.
2022-12-10 19:40:11 -05:00
👍 this [issue](https://github.com/balki/vimtabdiff/issues/1) for `pip install` support
# Screenshot
![image](https://user-images.githubusercontent.com/189196/206880555-c71b472c-144c-4c82-a4ab-f8a4fd36f7a5.png)
2022-12-07 18:04:27 -05:00
# Usage
```help
usage: vimtabdiff.py [-h] [--vim VIM] [--onlydiffs] pathA pathB
2022-12-07 18:04:27 -05:00
2023-02-28 20:58:54 -05:00
Show diff of files from two directories in vim tabs
2022-12-07 18:04:27 -05:00
2023-02-28 20:58:54 -05:00
positional arguments:
pathA
pathB
2022-12-07 18:04:27 -05:00
2023-02-28 20:58:54 -05:00
options:
-h, --help show this help message and exit
--vim VIM vim command to run
--onlydiffs only open files where there is a diff
2022-12-07 18:04:27 -05:00
```
2022-12-10 19:40:11 -05:00
## Relevant vim tips
2022-12-10 19:41:33 -05:00
* `gt` → Go to next tab
* `gT` → Go to previous tab
* `:tabr` → Go to first tab
* `:drop filenam<Tab>` → Go to the tab with filename
* `g<Tab>` → Go to last used tab (Works in vim version > 8.2.1401)
2023-01-05 16:04:40 -05:00
* `:set mouse=a` → Now clicking on a tab works
2022-12-10 19:41:33 -05:00
* `]c` → Go to next diff hunk
* `[c` → Go to previous diff hunk
* `do`, `dp` → Diff obtain, Diff put
2023-01-05 16:04:40 -05:00
* `zo`, `zc`, `zi` → Fold open, Fold close, toggle all folds
2022-12-10 19:40:11 -05:00
# See Git diffs
2022-12-07 18:04:27 -05:00
## Setup
```bash
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py $LOCAL $REMOTE'
git config --global alias.dt 'difftool --tool vimtabdiff --dir-diff'
```
## Usage
```bash
git dt <any git diff revision expression> # see `man gitrevisions`
git dt # Unstaged changes
git dt --staged # Staged changes
git dt HEAD~1 # Last commit
git di v1.0 v2.0 # diff between two tags
```
## Using custom vim command
Using clean vim without reading `vimrc`
2022-12-07 18:04:27 -05:00
```bash
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "vim --clean" $LOCAL $REMOTE'
```
Git config file (`~/.gitconfig`) should look like this
```TOML
2022-12-07 18:04:27 -05:00
[alias]
...
dt = difftool --tool vimtabdiff --dir-diff
[difftool "vimtabdiff"]
cmd = vimtabdiff.py --vim \"vim --clean\" $LOCAL $REMOTE
```
Using better diff algorithm
2022-12-07 18:04:27 -05:00
```bash
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "vim +\"set diffopt+=algorithm:patience\"" $LOCAL $REMOTE'
2022-12-07 18:04:27 -05:00
```
2022-12-07 18:04:27 -05:00
*Note:* Not tested in non-linux OS. But I guess it should work fine. Pull requests welcome if found any issues.
2022-12-07 18:04:27 -05:00
# Similar
2023-02-28 19:33:25 -05:00
* https://gist.github.com/Osse/4709787 is very similar, written as a `zsh` script.
* https://github.com/will133/vim-dirdiff is a Vim plugin that uses an interactive list of files instead of tabs.
* https://github.com/Soares/tabdiff.vim is a Vim plugin takes a list of files as aguments.
* [`:Git difftool -y`](https://github.com/tpope/vim-fugitive/blob/d507d00bd04794119beeb41da118774a96815b65/doc/fugitive.txt#L92) is a command from vim-fugitive which is a vim git plugin.