add Vimdiff function
This commit is contained in:
parent
53bd642a4f
commit
d542f117c9
2 changed files with 29 additions and 1 deletions
28
functions/Vimdiff.vim
Normal file
28
functions/Vimdiff.vim
Normal 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>
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
|
Loading…
Reference in a new issue