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

Gdiff: restore cursor position in original window #429

Closed
wants to merge 1 commit into from
Closed

Gdiff: restore cursor position in original window #429

wants to merge 1 commit into from

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Jan 19, 2014

Fixes #428

@tpope
Copy link
Owner

tpope commented Jan 19, 2014

Find a way to do this in the diff pane please. #36 explains why I switched the focus.

@tpope tpope closed this Jan 19, 2014
@blueyed
Copy link
Contributor Author

blueyed commented Jan 19, 2014

@tpope
While doing it in the diff pane could work somehow maybe, I find it more useful to stay in the original window, at the original position, instead of getting somewhere nearby (or thrown at the top like it's currently) in the diff pane.

#36 covers multiple issues: e.g. "stuck in diff mode" is not a problem with this pull request, as far as I can see.

@tpope
Copy link
Owner

tpope commented Jan 19, 2014

It is, actually. wincmd p can fail when other plugins are up to shenanigans on certain autocmd events. But the actual reason I changed the default is because it's awkward to close the diff window if you can't use <C-W>o (also covered in that big sprawly issue).

Losing the current line is unfortunate, and it's a tradeoff I deliberated for months before making. But I'm sticking to it. If you can find a way to restore it without regressing on window focus, great. You might look at winline().

@tpope
Copy link
Owner

tpope commented Jan 19, 2014

There's also 'cursorbind', but that's relatively new, so you'll need to cope gracefully if it's missing.

@blueyed
Copy link
Contributor Author

blueyed commented Jan 30, 2014

Please consider re-opening this PR, so that we can discuss this in the open field.

wincmd p can fail when other plugins are up to shenanigans on certain autocmd events.
Wouldn't nocautocmd help here?

But the actual reason I changed the default is because it's awkward to close the diff window if you can't use <C-W>o (also covered in that big sprawly issue).
I have a function/map for this. From inside of fugitive, a Gdiffoff command might be easier probably:

" Close any corresponding fugitive diff buffer.
function! MyCloseDiff()
  if (&diff == 0 || getbufvar('#', '&diff') == 0)
        \ && (bufname('%') !~ '^fugitive:' && bufname('#') !~ '^fugitive:')
    echom "Not in diff view."
    return
  endif

  diffoff " safety net / required to workaround powerline issue

" Close current buffer if alternate is not fugitive but current one is.
  if bufname('#') !~ '^fugitive:' && bufname('%') =~ '^fugitive:'
    if bufwinnr("#") == -1
" XXX: might not work reliable (old comment)
      b #
      bd #
    else
      bd
    endif
  else
    bd #
  endif
endfunction
nnoremap <Leader>gD :call MyCloseDiff()<cr>

You might look at winline().
What is your idea behind it? How is the window line relevant to get to the matching line in the diff buffer?

There's also 'cursorbind'

It is handled in s:diff_restore already, although not being set by fugitive (diff* activates it?!)

if has('cursorbind')
  let restore .= (&l:cursorbind ? ' ' : ' no') . 'cursorbind'
endif

@tpope
Copy link
Owner

tpope commented Jan 30, 2014

On Wed, Jan 29, 2014 at 9:19 PM, Daniel Hahler notifications@github.comwrote:

wincmd p can fail when other plugins are up to shenanigans on certain
autocmd events.
Wouldn't nocautocmd help here?

Possible but doubtful. The actual problematic command is probably the
split, and you can't disable them there without breaking everything.

You might look at winline().
What is your idea behind it? How is the window line relevant to get to the
matching line in the diff buffer?

Find the winline in the original buffer then go to the same winline in the
other buffer. Doing this probably involves bouncing between buffers so
above caveats apply. Although if you can preserve the use of diffsplit,
then hopefully only the cursor repositioning would fail in this broken
setup.

There's also 'cursorbind'

It is handled in s:diff_restore already, although not being set by
fugitive (diff* activates it?!)

if has('cursorbind')
let restore .= (&l:cursorbind ? ' ' : ' no') . 'cursorbind'
endif

Not sure it's ever being set, but see #122.

@tpope
Copy link
Owner

tpope commented Aug 21, 2019

I've ripped out all the hacks, as they are of dubious value on modern Vim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gdiff: Cursor position moves to top after last commit ("Focus diff window on :Gdiff")
2 participants