From d542f117c903dd0306bdace4e75d2adaa4de8610 Mon Sep 17 00:00:00 2001 From: Huaishun Hu Date: Mon, 4 Dec 2017 20:09:55 +0800 Subject: [PATCH] add Vimdiff function --- functions/Vimdiff.vim | 28 ++++++++++++++++++++++++++++ vimrcs/basic.vim | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 functions/Vimdiff.vim diff --git a/functions/Vimdiff.vim b/functions/Vimdiff.vim new file mode 100644 index 00000000..83970ec4 --- /dev/null +++ b/functions/Vimdiff.vim @@ -0,0 +1,28 @@ +" see: https://brookhong.github.io/2016/09/03/view-diff-file-side-by-side-in-vim.html + +function! Vimdiff() + let lines = getline(0, '$') + let la = [] + let lb = [] + for line in lines + if line[0] == '-' + call add(la, line[1:]) + elseif line[0] == '+' + call add(lb, line[1:]) + else + call add(la, line) + call add(lb, line) + endif + endfor + tabnew + set bt=nofile + vertical new + set bt=nofile + call append(0, la) + diffthis + exe "normal \l" + call append(0, lb) + diffthis +endfunction +autocmd FileType diff nnoremap vd :call Vimdiff() + diff --git a/vimrcs/basic.vim b/vimrcs/basic.vim index 6c3d6dd3..d371d96a 100644 --- a/vimrcs/basic.vim +++ b/vimrcs/basic.vim @@ -63,7 +63,7 @@ nmap w :w! " :W sudo saves the file " (useful for handling the permission-denied error) -command W w !sudo tee % > /dev/null +command! W w !sudo tee % > /dev/null """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""