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 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 diff --git a/plugin/DirDiff.vim b/plugin/DirDiff.vim index 58e6146..2564a65 100644 --- a/plugin/DirDiff.vim +++ b/plugin/DirDiff.vim @@ -308,13 +308,16 @@ endif if !exists("g:DirDiffTextOnlyInCenter") let g:DirDiffTextOnlyInCenter = ": " endif +" If true, the buffer is deleted after being displayed in a diff +if !exists("g:DirDiffBufferDelete") + let g:DirDiffBufferDelete = 1 +endif " Set some script specific variables: " let s:DirDiffFirstDiffLine = 6 let s:DirDiffALine = 1 let s:DirDiffBLine = 2 -let s:DirDiffIsRunning = 0 " -- Variables used in various utilities if has("unix") @@ -368,8 +371,8 @@ endif function! DirDiff(srcA, srcB) - if(s:DirDiffIsRunning == 0) - let s:DirDiffIsRunning = 1 + tabedit + if &guioptions =~# 'T' aunmenu ToolBar.GUI amenu ToolBar.PrevChange [c tmenu ToolBar.PrevChange Previous Change @@ -390,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") @@ -434,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 @@ -475,9 +474,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 @@ -563,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) @@ -616,12 +614,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 @@ -665,8 +673,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" @@ -713,12 +724,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 - exec thisWindow.'wincmd w' + wincmd k + normal! gg]c endfunction " Ask the user to save if the buffer is modified @@ -863,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")