diff options
author | zlg <zlg@zlg.space> | 2018-11-12 21:06:37 -0800 |
---|---|---|
committer | zlg <zlg@zlg.space> | 2018-11-12 21:06:37 -0800 |
commit | 5279a9997af35f5940c5851e46c4247d38a6ee0a (patch) | |
tree | b265d93312ac4a50715b59d4e5177a0ab2bd6a03 | |
parent | Add PICO-8 file preferences (diff) | |
download | vimrc-5279a9997af35f5940c5851e46c4247d38a6ee0a.tar.gz vimrc-5279a9997af35f5940c5851e46c4247d38a6ee0a.tar.bz2 vimrc-5279a9997af35f5940c5851e46c4247d38a6ee0a.tar.xz vimrc-5279a9997af35f5940c5851e46c4247d38a6ee0a.zip |
Add BufDiff()
-rw-r--r-- | vimrc | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -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 |