public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
diff --git a/scmdiff.vim b/scmdiff.vim
index 18f4e1b..1ee8250 100644
--- a/scmdiff.vim
+++ b/scmdiff.vim
@@ -2,8 +2,11 @@
" Home: http://github.com/ghewgill/vim-scmdiff
" Default commands:
-" \d Toggle diff view on/off
-" :D rev Difference between current and rev
+" \d Toggle diff view on/off
+" :D rev Difference between current and rev
+" \s Toggle split view/non-split view
+" :Dsplit Set Split view as default
+" :Dnosplit Set no Split view as default
"
" You can change the highlighting by adding the following to your
" .vimrc file and customizing as necessary. (or just uncomment them here):
@@ -19,30 +22,62 @@ endif
let loadedScmDiff = 1
map <silent> <Leader>d :call <SID>scmToggle()<CR>
+map <silent> <Leader>s :call <SID>scmSplitToggle()<CR>
noremap <unique> <script> <plug>Dh :call <SID>scmDiff("h")<CR>
com! -bar -nargs=? D :call s:scmDiff(<f-args>)
+com! -bar -nargs=? Dsplit :call s:scmSplitToggle(1)
+com! -bar -nargs=? Dnosplit :call s:scmSplitToggle(0)
let g:scmDiffRev = ''
function! s:scmToggle()
- if exists('b:scmDiffOn') && b:scmDiffOn == 1
- let b:scmDiffOn = 0
+ if exists('t:scmDiffOn') && t:scmDiffOn == 1
+ let t:scmDiffOn = 0
+ if exists('t:scmDiffSplit') && t:scmDiffSplit == 1
+ hide
+ endif
set nodiff
- exe 'bdelete ' . b:scmDiffTmpfile
+ exe 'bdelete ' . t:scmDiffTmpfile
echohl DiffDelete | echon "scmdiff Disabled" | echohl None
else
call s:scmDiff()
- if exists('b:scmDiffOn') && b:scmDiffOn == 1
+ if exists('t:scmDiffOn') && t:scmDiffOn == 1
echohl DiffAdd | echon "scmdiff Enabled" | echohl None
endif
endif
endfunction
+function! s:scmSplitToggle(...)
+
+ if a:0 == 1
+ let t:scmDiffSplit = a:1
+ else
+ let l:toggle = 0
+ if exists('t:scmDiffOn') && t:scmDiffOn == 1
+ let l:toggle = 1
+ call s:scmToggle()
+ endif
+
+ if exists('t:scmDiffSplit') && t:scmDiffSplit == 1
+ let t:scmDiffSplit = 0
+ echohl DiffDelete | echon "scmDiffSplit Disabled" | echohl None
+ else
+ let t:scmDiffSplit = 1
+ echohl DiffAdd | echon "scmDiffSplit Enabled" | echohl None
+ endif
+
+ if l:toggle == 1
+ call s:scmToggle()
+ endif
+ endif
+
+endfunction
+
function! s:scmRefresh()
- if exists('b:scmDiffOn') && b:scmDiffOn == 1
+ if exists('t:scmDiffOn') && t:scmDiffOn == 1
call s:scmDiff()
endif
@@ -100,13 +135,12 @@ function! s:scmDiff(...)
return
endif
- if exists('b:scmDiffOn') && b:scmDiffOn == 1
- let b:scmDiffOn = 0
+ if exists('t:scmDiffOn') && t:scmDiffOn == 1
+ let t:scmDiffOn = 0
set nodiff
- exe 'bdelete ' . b:scmDiffTmpfile
+ exe 'bdelete ' . t:scmDiffTmpfile
endif
- let b:scmDiffOn = 1
let view = winsaveview()
if a:0 == 1
@@ -121,8 +155,8 @@ function! s:scmDiff(...)
endif
let ftype = &filetype
- let b:scmDiffTmpfile = tempname()
- let cmd = 'cat ' . bufname('%') . ' > ' . b:scmDiffTmpfile
+ let t:scmDiffTmpfile = tempname()
+ let cmd = 'cat ' . bufname('%') . ' > ' . t:scmDiffTmpfile
let cmdOutput = system(cmd)
let tmpdiff = tempname()
let cmd = 'cd ' . g:scmBufPath . ' && ' . g:scmDiffCommand . ' ' . g:scmDiffRev . ' ' . expand('%:t') . ' > ' . tmpdiff
@@ -134,7 +168,7 @@ function! s:scmDiff(...)
return
endif
- let cmd = 'patch -R -p0 ' . b:scmDiffTmpfile . ' ' . tmpdiff
+ let cmd = 'patch -R -p0 ' . t:scmDiffTmpfile . ' ' . tmpdiff
let cmdOutput = system(cmd)
if v:shell_error && cmdOutput != ''
@@ -143,24 +177,27 @@ function! s:scmDiff(...)
endif
if a:0 > 0 && a:1 == 'h'
- exe 'diffsplit' . b:scmDiffTmpfile
+ exe 'diffsplit' . t:scmDiffTmpfile
else
- exe 'vert diffsplit' . b:scmDiffTmpfile
+ exe 'vert diffsplit' . t:scmDiffTmpfile
endif
exe 'set filetype=' . ftype
- hide
- if doWrap == 1
- set wrap "Restore the state of wrap
- endif
+ if !exists("t:scmDiffSplit") || t:scmDiffSplit == 0
+ hide
+ if doWrap == 1
+ set wrap "Restore the state of wrap
+ endif
- set foldcolumn=0
- set foldlevel=100
- set diffopt= " removed filler so we don't show deleted lines
- set noscrollbind
+ set foldcolumn=0
+ set foldlevel=100
+ set diffopt= " removed filler so we don't show deleted lines
+ set noscrollbind
+ endif
call winrestview(view)
+ let t:scmDiffOn = 1
endfunction

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.