From a4b38794334eee1d8911604af2e2360f7bcad194 Mon Sep 17 00:00:00 2001 From: mMontu Date: Mon, 12 Jan 2015 10:41:42 -0200 Subject: [PATCH 1/9] Include basic help file --- doc/DirDiff.txt | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 doc/DirDiff.txt diff --git a/doc/DirDiff.txt b/doc/DirDiff.txt new file mode 100755 index 0000000..9b4c5ad --- /dev/null +++ b/doc/DirDiff.txt @@ -0,0 +1,101 @@ +*DirDiff.vim* A plugin to diff and merge two directories recursively + +Text copied from www.vim.org/scripts/script.php?script_id=102 in 14/06/2012 +script karma Rating 1780/502, Downloaded by 11272 +created by William Lee + +description +This is a utility that performs a recursive diff on two directories and +generate a diff "window". Based on that window you can perform various diff +operations such as opening two files in Vim's diff mode, copy the file or +directory recursively to the other, or remove the directory tree from the +source directory. + + Doing the following will generate a diff window. + + :DirDiff + e.g. + :DirDiff ../something/dir1 /usr/bin/somethingelse/dir2 + + The following commands can be used inside the diff window: + 'Enter','o' - Diff open: open the diff file(s) where your cursor is at + 's' - Synchronize the current diff. You can also select + a range (through visual) and press 's' to synchronize differences + across a range. + + - There are 6 Options you can choose when you hit 's': + 1. A -> B + Copy A to overwrite B + If A's file actually points to a directory, it'll copy it to B + recursively. + 2. B -> A + Copy B to overwrite A + If B's file actually points to a directory, it'll copy it to A + recursively. + 3. Always A + For the rest of the items that you've selected, + synchronize like (1). + 4. Always B + For the rest of the items that you've selected, + synchronize like (2). + 5. Skip + Skip this diff entry. + 6. Cancel + Quit the loop and exit. + + 'u' - Diff update: update the diff window + 'x' - Sets the exclude pattern, separated by ',' + 'i' - Sets the ignore pattern, separated by ',' + 'a' - Sets additional arguments for diff, eg. -w to ignore white space, + etc. + 'q' - Quit DirDiff + + The following comamnds can be used in the Vim diff mode + \dg - Diff get: maps to :diffget + \dp - Diff put: maps to :diffput + \dj - Diff next: (think j for down) + \dk - Diff previous: (think k for up) + + You can set the following DirDiff variables. You can add the following + "let" lines in your .vimrc file. + + Sets default exclude pattern: + let g:DirDiffExcludes = "CVS,*.class,*.exe,.*.swp" + + Sets default ignore pattern: + let g:DirDiffIgnore = "Id:,Revision:,Date:" + + If DirDiffSort is set to 1, sorts the diff lines. + let g:DirDiffSort = 1 + + Sets the diff window (bottom window) height (rows) + let g:DirDiffWindowSize = 14 + + Ignore case during diff + let g:DirDiffIgnoreCase = 0 + + Dynamically figure out the diff text. If you are using and i18n version + of diff, this will try to get the specific diff text during runtime. It's + turned off by default. If you are always targetting a specific version of + diff, you can turn this off and set the DirDiffText* variables + accordingly. + let g:DirDiffDynamicDiffText = 0 + + String used for the English equivalent "Files " + let g:DirDiffTextFiles = "Files " + + String used for the English equivalent " and " + let g:DirDiffTextAnd = " and " + + String used for the English equivalent " differ") + let g:DirDiffTextDiffer = " differ" + + String used for the English equivalent "Only in ") + let g:DirDiffTextOnlyIn = "Only in " + + +install details + Put this file in your ~/.vim/plugin + + +vim: tw=78:ts=8:ft=help:fdm=marker From 9b9cb5c92f363c31986ebf42c16be1f414b10dea Mon Sep 17 00:00:00 2001 From: mMontu Date: Mon, 12 Jan 2015 10:42:55 -0200 Subject: [PATCH 2/9] Include .gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b08bd7d --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +############# +# various # +############# +tags +*.swp +.netrwhist From 0d854ec2b97c833ec61cf971263248b7e8e94464 Mon Sep 17 00:00:00 2001 From: mMontu Date: Mon, 12 Jan 2015 13:25:20 -0200 Subject: [PATCH 3/9] Start with cursor on the first difference * Always the first difference - the current behavior seems be jumping to the cursor position when the file was last opened for edition. Sometimes some differences are missed because the buffers open with only the last differences on the screen. * Move the cursor to the first difference - the current behavior seems to be leaving the cursor at the diff window. I've found that most of the time it is necessary to check the changes on many files, and using \dj and \dk leaves the cursor on diff window, so it is necessary to move back to the diff windows. --- plugin/DirDiff.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/DirDiff.vim b/plugin/DirDiff.vim index 58e6146..3ab0c58 100644 --- a/plugin/DirDiff.vim +++ b/plugin/DirDiff.vim @@ -718,7 +718,8 @@ function! DirDiffOpen() echo "There is no diff at the current line!" endif - exec thisWindow.'wincmd w' + wincmd p + normal gg]c endfunction " Ask the user to save if the buffer is modified From a59bb382ce3327f6b3da948d015c3db390882b55 Mon Sep 17 00:00:00 2001 From: mMontu Date: Mon, 12 Jan 2015 13:34:49 -0200 Subject: [PATCH 4/9] Option to close instead of deleting buffers The current behavior uses `:bd` to close a diff window after it is displayed on the screen, which causes any other windows displaying that file to be closed. The option g:DirDiffBufferDelete allows to use `:q` instead. In this case the `:diffoff` is also necessary to avoid subsequent diffs to be displayed incorrectly. --- plugin/DirDiff.vim | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugin/DirDiff.vim b/plugin/DirDiff.vim index 3ab0c58..3371f69 100644 --- a/plugin/DirDiff.vim +++ b/plugin/DirDiff.vim @@ -308,6 +308,10 @@ endif if !exists("g:DirDiffTextOnlyInCenter") let g:DirDiffTextOnlyInCenter = ": " endif +" Selects if a buffer is deleted after it is displayed in a diff +if !exists("g:DirDiffBufferDelete") + let g:DirDiffBufferDelete = 1 +endif " Set some script specific variables: " @@ -616,12 +620,22 @@ function! CloseDiffWindows() wincmd k " Ask the user to save if buffer is modified call AskIfModified() - bd! + if g:DirDiffBufferDelete + bd! + else + diffoff + q + endif " User may just have one window opened, we may not need to close " the second diff window if (&diff) call AskIfModified() - bd! + if g:DirDiffBufferDelete + bd! + else + diffoff + q + endif endif endif endfunction From 944eaf365a211b6134704a33d15d1a98c3a003df Mon Sep 17 00:00:00 2001 From: mMontu Date: Mon, 12 Jan 2015 13:39:57 -0200 Subject: [PATCH 5/9] Avoid error beep in some conditions --- plugin/DirDiff.vim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/DirDiff.vim b/plugin/DirDiff.vim index 3371f69..37f4d0b 100644 --- a/plugin/DirDiff.vim +++ b/plugin/DirDiff.vim @@ -679,8 +679,11 @@ function! DirDiffOpen() call CloseDiffWindows() - " Ensure we're in the right window - exec thisWindow.'wincmd w' + " Ensure we're in the right window - check if there is any splits before + " executing wincmd to avoid error beep + if winnr("$") != 1 + exec thisWindow.'wincmd w' + endif let line = getline(".") " Parse the line and see whether it's a "Only in" or "Files Differ" From 199dd6cb46dcc6ba3e6a98047f979d0bf8bb1583 Mon Sep 17 00:00:00 2001 From: mMontu Date: Mon, 12 Jan 2015 13:47:49 -0200 Subject: [PATCH 6/9] Display the results on a new tabpage --- plugin/DirDiff.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/DirDiff.vim b/plugin/DirDiff.vim index 37f4d0b..0329785 100644 --- a/plugin/DirDiff.vim +++ b/plugin/DirDiff.vim @@ -373,6 +373,7 @@ endif function! DirDiff(srcA, srcB) if(s:DirDiffIsRunning == 0) + tabedit let s:DirDiffIsRunning = 1 aunmenu ToolBar.GUI amenu ToolBar.PrevChange [c @@ -735,7 +736,7 @@ function! DirDiffOpen() echo "There is no diff at the current line!" endif - wincmd p + wincmd k normal gg]c endfunction From 201bf35a17bd3c9efc3fe2638d7c8b9f731d5c1c Mon Sep 17 00:00:00 2001 From: mMontu Date: Mon, 12 Jan 2015 15:53:47 -0200 Subject: [PATCH 7/9] Small adjustments --- plugin/DirDiff.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/DirDiff.vim b/plugin/DirDiff.vim index 0329785..8f3e6b4 100644 --- a/plugin/DirDiff.vim +++ b/plugin/DirDiff.vim @@ -308,7 +308,7 @@ endif if !exists("g:DirDiffTextOnlyInCenter") let g:DirDiffTextOnlyInCenter = ": " endif -" Selects if a buffer is deleted after it is displayed in a diff +" If true, the buffer is deleted after being displayed in a diff if !exists("g:DirDiffBufferDelete") let g:DirDiffBufferDelete = 1 endif @@ -731,13 +731,13 @@ function! DirDiffOpen() call DirDiffResize() exe (b:currentDiff) " Center the line - exe ("normal z.") + exe ("normal! z.") else echo "There is no diff at the current line!" endif wincmd k - normal gg]c + normal! gg]c endfunction " Ask the user to save if the buffer is modified From 1cea674b60e52a6b161864979379ef4e179b0585 Mon Sep 17 00:00:00 2001 From: mMontu Date: Fri, 16 Jan 2015 11:13:26 -0200 Subject: [PATCH 8/9] Use meaningful name on the DiffBuffer --- plugin/DirDiff.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/DirDiff.vim b/plugin/DirDiff.vim index 8f3e6b4..54cc0fd 100644 --- a/plugin/DirDiff.vim +++ b/plugin/DirDiff.vim @@ -480,9 +480,11 @@ function! DirDiff(srcA, srcB) 0 setlocal nomodified setlocal nomodifiable - setlocal buftype=nowrite + setlocal buftype=nofile setlocal bufhidden=delete + setlocal noswapfile setlocal nowrap + file DirDiff " Set up local key bindings From e5e38c5f58c7abc68c390d6a5e2ee2348eb72d2a Mon Sep 17 00:00:00 2001 From: mMontu Date: Tue, 20 Jan 2015 14:47:23 -0200 Subject: [PATCH 9/9] Remove s:DirDiffIsRunning --- plugin/DirDiff.vim | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/plugin/DirDiff.vim b/plugin/DirDiff.vim index 54cc0fd..2564a65 100644 --- a/plugin/DirDiff.vim +++ b/plugin/DirDiff.vim @@ -318,7 +318,6 @@ endif let s:DirDiffFirstDiffLine = 6 let s:DirDiffALine = 1 let s:DirDiffBLine = 2 -let s:DirDiffIsRunning = 0 " -- Variables used in various utilities if has("unix") @@ -372,9 +371,8 @@ endif function! DirDiff(srcA, srcB) - if(s:DirDiffIsRunning == 0) - tabedit - let s:DirDiffIsRunning = 1 + tabedit + if &guioptions =~# 'T' aunmenu ToolBar.GUI amenu ToolBar.PrevChange [c tmenu ToolBar.PrevChange Previous Change @@ -395,9 +393,6 @@ function! DirDiff(srcA, srcB) tmenu ToolBar.UpdateDiff Update Diff amenu ToolBar.QuitDiff :call DirDiffQuit () tmenu ToolBar.QuitDiff Quit Diff - else - echo "DirDiff is running" - return endif " Setup let DirDiffAbsSrcA = fnamemodify(expand(a:srcA, ":p"), ":p") @@ -439,7 +434,6 @@ function! DirDiff(srcA, srcB) let error = DirDiffExec(cmd, 0) if (error == 0) redraw | echom "diff found no differences - directories match." - let s:DirDiffIsRunning = 0 return endif silent exe "edit ".DiffBuffer @@ -570,29 +564,26 @@ function! DirDiffQuit() let in = confirm ("Are you sure you want to quit DirDiff?", "&Yes\n&No", 2) if (in == 1) call CloseDiffWindows() - aunmenu ToolBar.PrevChange - aunmenu ToolBar.NextChange - aunmenu ToolBar.PutChange - aunmenu ToolBar.GetChange - aunmenu ToolBar.-DDSep2- - aunmenu ToolBar.PrevFile - aunmenu ToolBar.NextFile - aunmenu ToolBar.SyncFiles - aunmenu ToolBar.UpdateDiff - aunmenu ToolBar.QuitDiff - amenu ToolBar.GUI :call DirDiffGUI () - tmenu ToolBar.GUI Start DirDiff with GUI + if &guioptions =~# 'T' + aunmenu ToolBar.PrevChange + aunmenu ToolBar.NextChange + aunmenu ToolBar.PutChange + aunmenu ToolBar.GetChange + aunmenu ToolBar.-DDSep2- + aunmenu ToolBar.PrevFile + aunmenu ToolBar.NextFile + aunmenu ToolBar.SyncFiles + aunmenu ToolBar.UpdateDiff + aunmenu ToolBar.QuitDiff + amenu ToolBar.GUI :call DirDiffGUI () + tmenu ToolBar.GUI Start DirDiff with GUI + endif bd! endif - let s:DirDiffIsRunning = 0 endfun " Open GUI for DirDiff function! DirDiffGUI() - if(s:DirDiffIsRunning == 1) - echo "DirDiff is running" - return - endif let workingDir = $HOME.'/workspace/' let lft = browsedir("Select the left side to compare", workingDir) @@ -884,7 +875,6 @@ function! DirDiffSyncHelper(AB, line) else echo "There is no diff here!" " Error - let s:DirDiffIsRunning = 0 return 1 endif if (operation == "Copy")