From 5279a9997af35f5940c5851e46c4247d38a6ee0a Mon Sep 17 00:00:00 2001 From: zlg Date: Mon, 12 Nov 2018 21:06:37 -0800 Subject: Add BufDiff() --- vimrc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/vimrc b/vimrc index 959b9e1..54a49d7 100644 --- a/vimrc +++ b/vimrc @@ -283,4 +283,51 @@ function! InsertDOW() " {{{2 " Return the value in the x register let @x = tmpx endfunction +" }}} +" BufDiff, by zlg {{{2 +" Function: BufDiff +" Author: zlg +" Date: 2018-10-12 +" License: GNU GPL, version 3 +" 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(""), "^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 -- cgit v1.2.3-54-g00ecf