Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve #9 #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions plugin/mergetool.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

" check whether this script is already loaded
if exists("g:loaded_mergetool")
finish
Expand All @@ -20,34 +19,22 @@ nnoremap <silent> <Plug>(MergetoolToggle) :<C-u>call mergetool#toggle()<CR>
" {{{ Diff exchange

" Do either diffget or diffput, depending on given direction
" and whether the window has adjacent window in a given direction
" h|<left> + window on right = diffget from right win
" h|<left> + no window on right = diffput to left win
" l|<right> + window on left = diffget from left win
" l|<right> + no window on left = diffput to right win
" Same logic applies for vertical directions: 'j' and 'k'

let s:directions = {
\ 'h': 'l',
\ 'l': 'h',
\ 'j': 'k',
\ 'k': 'j' }
" and whether the current window is modifiable
" If current window is modifiable, get the diff, otherwise put it
" If none of the windows are modifiable, VIM raises error automatically

function s:DiffExchange(dir)
let oppdir = s:directions[a:dir]

let winoppdir = s:FindWindowOnDir(oppdir)
let winoppdir = s:FindWindowOnDir(a:dir)
if (winoppdir != -1)
execute "diffget " . winbufnr(winoppdir)
else
let windir = s:FindWindowOnDir(a:dir)
if (windir != -1)
execute "diffput " . winbufnr(windir)
if &modifiable
execute "diffget " . winbufnr(winoppdir)
else
echohl WarningMsg
echo 'Cannot exchange diff. Found only single window'
echohl None
execute "diffput " . winbufnr(winoppdir)
endif
else
echohl WarningMsg
echo 'Cannot exchange diff. Source/Destination window not found.'
echohl None
endif
endfunction

Expand Down