any-jump.vim icon indicating copy to clipboard operation
any-jump.vim copied to clipboard

Last cursor position lost

Open jeebak opened this issue 4 years ago • 3 comments

HI there,

I just installed this plugin and am enjoying it so far, but I'm running into unexpected behavior. After invoking AnyJump it seems the cursor is moved to the top of the buffer before the popup is opened, and worse the cursor is left near the top of the buffer when the popup's closed (via esc/q.) I'd've expected the cursor to be placed back at the original position before AnyJump was invoked. I looked at the README and the help. Is there a setting or caveat that I've overlooked?

Thanks!

jeebak avatar May 17 '21 22:05 jeebak

I just wanted to leave a note that I'm experiencing this as well running Vim 8.2 under Cygwin (yuck, I know), in case there was any questions of NeoVim vs Vim or versioning. I'm available as a guinea pig for testing fixes as well.

It's a frequent use case that I'll hit esc after realizing that the term I have under the cursor is not the one I want to search (huge code-base).

matthewmoto avatar Jun 02 '21 13:06 matthewmoto

The workaround I'm using is wrapping the call using bling's Preserve function, thusly:

  function! Preserve(command)
    " preparation: save last search, and cursor position.
    let _s=@/
    let l = line(".")
    let c = col(".")
    " do the business:
    execute a:command
    " clean up: restore previous search history, and cursor position
    let @/=_s
    call cursor(l, c)
  endfunction

  Plug 'pechorin/any-jump.vim' "{{{
    " Jump to any definition and references 👁 IDE madness without overhead 🚀

    let g:any_jump_disable_default_keybindings = 1
    let g:any_jump_list_numbers = 1

    nnoremap <leader>j :call Preserve("AnyJump")<CR>
    xnoremap  <leader>j :call Preserve("AnyJump")<CR>
  "}}}

jeebak avatar Jun 02 '21 19:06 jeebak

I'm seeing this as well, VIM 9.0 on Linux.

And thanks a lot, @jeebak, your workaround works great for me, too!

alexbarton avatar Apr 26 '24 11:04 alexbarton