summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vimrc47
1 files changed, 47 insertions, 0 deletions
diff --git a/vimrc b/vimrc
index 959b9e1..54a49d7 100644
--- a/vimrc
+++ b/vimrc
@@ -283,4 +283,51 @@ function! <SID>InsertDOW() " {{{2
" Return the value in the x register
let @x = tmpx
endfunction
+" }}}
+" BufDiff, by zlg {{{2
+" Function: BufDiff
+" Author: zlg <zlg+viml@zlg.space>
+" Date: 2018-10-12
+" License: GNU GPL, version 3 <https://gnu.org/licenses/gpl-3.0.html>
+" Description: Open a new tab page with two or three buffers and enter diff mode.
+" Long Description:
+" BufDiff accepts two or three buffer arguments and opens a new tab page to
+" work with them in diff mode. This ensures that your existing window and
+" buffer layout is preserved while providing an easy way to enter a diff
+" session. The arguments can be any argument that can also be passed to
+" the ":buffer" Ex-command, including partial filenames (if quoted).
+function! BufDiff(buf1, buf2, ...)
+ let fname = substitute(expand("<sfile>"), "^function ", "", "")
+ if a:0 > 1
+ echohl ErrorMsg
+ echomsg l:fname . ": This function accepts a maximum of three arguments."
+ echohl None
+ return
+ endif
+
+ " Check for a third buffer, which will default to zero if not present
+ let a:buf3 = get(a:, 1, 0)
+
+ if !bufexists(a:buf1) || !bufexists(a:buf2) || (a:0 == 1 && !bufexists(a:buf3))
+ echohl ErrorMsg
+ echomsg l:fname . ": One or more buffer number(s) not found!"
+ echohl None
+ return
+ else
+ tabnew
+ exe ":buffer " . a:buf1
+ diffthis
+ vsplit
+ exe ":buffer " . a:buf2
+ diffthis
+ if a:buf3
+ vsplit
+ exe ":buffer " . a:buf3
+ diffthis
+ endif
+ return
+ endif
+endfunction
+" }}}
+
" vim: foldmethod=marker