Skip to content

appblue/vimtabdiff

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 

Repository files navigation

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

    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
    curl -o ~/bin/vimtabdiff.py "https://raw.githubusercontent.com/balki/vimtabdiff/br-py38/vimtabdiff.py"

    chmod +x ~/bin/vimtabdiff.py

You may need to add ~/bin to your PATH variable if not already done. See here for help. 👍 this issue for pip install support

Screenshot

image

Usage

usage: vimtabdiff.py [-h] [--vim VIM] [--onlydiffs] pathA pathB

Show diff of files from two directories in vim tabs

positional arguments:
  pathA
  pathB

options:
  -h, --help                        show this help message and exit
  --vim VIM                         vim command to run
  --exclude path_glob1,path_glob2   comma separated list of files/folders to exclude
  --match regex1,regex2             comma separated list of regular expressions to limit the scope to only paths matching one of the expressions (e.g. 'components.*,http')
  --git                             shortcut to add glob '**/.git' to exclusion list
  --onlydiffs                       only open files where there is a diff

Usage example

    # Show diff of files in two directories
    vimtabdiff.py path/to/dirA path/to/dirB

    # Show diff of files in two directories, excluding folder matching '**/.git' fileglob
    vimtabdiff.py --git path/to/dirA path/to/dirB

    # Show diff of files in two directories, excluding .git folder and *.pyc files in top level directories
    vimtabdiff.py --exclude '**/.git,*.pyc' path/to/dirA path/to/dirB

    # Show diff of files in two directories, only showing files with diffs
    vimtabdiff.py --onlydiffs path/to/dirA path/to/dirB

    # Show diff of files in two directories, only showing files with full paths matching any of the regexes
    vimtabdiff.py --match 'components.*,http' path/to/dirA path/to/dirB

The --match option is useful when you want to limit the scope of the diff to only certain files or directories. For example, if you have a large project and you only want to see changes in the components directory or files that contain http, you can use this option. It's applied to the full path of the files, so you can use it to match directories as well, after applying the --exclude option.

Relevant vim tips

  • 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)
  • :set mouse=a → Now clicking on a tab works
  • ]c → Go to next diff hunk
  • [c → Go to previous diff hunk
  • do, dp → Diff obtain, Diff put
  • zo, zc, zi → Fold open, Fold close, toggle all folds

See Git diffs

Setup

    git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py $LOCAL $REMOTE'
    git config --global alias.dt 'difftool --tool vimtabdiff --dir-diff'

Usage

    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

    git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "vim --clean" $LOCAL $REMOTE'

Git config file (~/.gitconfig) should look like this

    [alias]
            ...
            dt = difftool --tool vimtabdiff --dir-diff
    [difftool "vimtabdiff"]
            cmd = vimtabdiff.py --vim \"vim --clean\" $LOCAL $REMOTE

Using better diff algorithm

    git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "vim +\"set diffopt+=algorithm:patience\"" $LOCAL $REMOTE'

Note: Not tested in non-linux OS. But I guess it should work fine. Pull requests welcome if found any issues.

Similar

About

Show diff of files from two directories in vim tabs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%