Skip to content

Commit

Permalink
Add "hex mode" and "wrap mode" support
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Chen <chenkaie@gmail.com>
  • Loading branch information
chenkaie committed Oct 26, 2020
1 parent 6e4b04c commit b075140
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
11 changes: 9 additions & 2 deletions doc/dirdiff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ REQUIREMENTS *dirdiff-requirements*
tested this on cygwin's version on Windows. If you have a diff that
doesn't support -x or -I flag, do not set variable g:DirDiffExcludes and
g:DirDiffIgnore to "". It should still work.
- On Windows, you need to have "xcopy", "copy", "del", and "rd" in your
- On Windows, you need to have "xcopy", "copy", "del" "rd" and "xxd" in your
path.
- On Unix, you need to have "rm" and "cp" in your path.
- On Unix, you need to have "rm", "cp" and "xxd" in your path.

INSTALLATION *dirdiff-installation*

Expand Down Expand Up @@ -93,6 +93,12 @@ The following commands can be used inside the diff window:
<a> Sets additional arguments for diff, eg. -w to ignore
white space, etc.

*dirdiff-h*
<h> Toggle xxd hex mode on or off.

*dirdiff-w*
<w> Toggle wrap and nowrap mode

<q> Quit DirDiff

The following comamnds can be used in the Vim diff mode if this is global flag
Expand Down Expand Up @@ -263,6 +269,7 @@ THANKS *dirdiff-thanks*

HISTORY *dirdiff-history*

1.1.7 - Added support for "hex mode" and "wrap mode"
1.1.6 - Fixed problem with vim 8.2 where the :drop would not work with
wildignore. Added option to set shell.
1.1.5 - Fixed split windows problems caused by some .vimrc settings.
Expand Down
60 changes: 59 additions & 1 deletion plugin/dirdiff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function! <SID>DirDiff(srcA, srcB)
else
call append(2, "Usage: <Enter>/'o'=open,'s'=sync,'q'=quit")
endif
call append(3, "Options: 'u'=update,'x'=set excludes,'i'=set ignore,'a'=set args" )
call append(3, "Options: 'u'=update,'x'=set excludes,'i'=set ignore,'a'=set args, 'h'=hex mode, 'w'=wrap mode")
call append(4, "Diff Args:" . cmdarg)
call append(5, "")
" go to the beginning of the file
Expand All @@ -297,6 +297,8 @@ function! <SID>DirDiff(srcA, srcB)
nnoremap <buffer> x :call <SID>ChangeExcludes()<CR>
nnoremap <buffer> a :call <SID>ChangeArguments()<CR>
nnoremap <buffer> i :call <SID>ChangeIgnore()<CR>
nnoremap <buffer> h :call <SID>DirDiffHexmode()<CR>
nnoremap <buffer> w :call <SID>DirDiffWrapmode()<CR>
nnoremap <buffer> q :call <SID>DirDiffQuit()<CR>
nnoremap <buffer> o :call <SID>DirDiffOpen()<CR>
Expand Down Expand Up @@ -377,6 +379,62 @@ function! <SID>SaveDiffWindowsIfModified()
endif
endfunction

" Toggle hexmode from http://vim.wikia.com/wiki/Hex
function <SID>ToggleHex()
" hex mode should be considered a read-only operation
" save values for modified and read-only for restoration later,
" and clear the read-only flag for now
let l:modified=&mod
let l:oldreadonly=&readonly
let &readonly=0
let l:oldmodifiable=&modifiable
let &modifiable=1
if !exists("b:editHex") || !b:editHex
" save old options
let b:oldft=&ft
let b:oldbin=&bin
" set new options
setlocal binary " make sure it overrides any textwidth, etc.
let &ft="xxd"
" set status
let b:editHex=1
" switch to hex editor
silent %!xxd
else
" restore old options
let &ft=b:oldft
if !b:oldbin
setlocal nobinary
endif
" set status
let b:editHex=0
" return to normal editing
silent %!xxd -r
endif
" restore values for modified and read only state
let &mod=l:modified
let &readonly=l:oldreadonly
let &modifiable=l:oldmodifiable
endfunction

function! <SID>DirDiffHexmode()
wincmd k
call <SID>ToggleHex()
wincmd l
call <SID>ToggleHex()
" Go back to the diff window
wincmd j
endfunction

function! <SID>DirDiffWrapmode()
wincmd k
setlocal wrap!
wincmd l
setlocal wrap!
" Go back to the diff window
wincmd j
endfunction

function! <SID>EscapeFileName(path)
if (v:version >= 702)
return fnameescape(a:path)
Expand Down

0 comments on commit b075140

Please sign in to comment.