1
0
Fork 0
mirror of synced 2024-11-23 01:05:34 -05:00

add Vimdiff function

This commit is contained in:
Huaishun Hu 2017-12-04 20:09:55 +08:00
parent 53bd642a4f
commit d542f117c9
2 changed files with 29 additions and 1 deletions

28
functions/Vimdiff.vim Normal file
View file

@ -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 \<C-W>l"
call append(0, lb)
diffthis
endfunction
autocmd FileType diff nnoremap <silent> <leader>vd :call Vimdiff()<CR>

View file

@ -63,7 +63,7 @@ nmap <leader>w :w!<cr>
" :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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""