leap.nvim icon indicating copy to clipboard operation
leap.nvim copied to clipboard

The real cursor stays in its original position after autojumping

Open ggandor opened this issue 2 years ago • 6 comments

https://github.com/ggandor/flit.nvim/issues/3

ggandor avatar Oct 22 '22 21:10 ggandor

fyi: this is a Neovim issue that will have to be eventually fixed upstream, but I've fixed this for now for people using Noice. https://github.com/folke/noice.nvim/commit/42722b24e8bf63e78101bfe77c569d891604d01e

I hide the cursor whenever some plugin requests input :)

folke avatar Oct 24 '22 14:10 folke

Is there any update about when this issue will be fixed? I am trying out leap/flit as a replacement for sneak, but this bug is quite distracting, since I have to do the next action while trusting that the cursor has jumped to the desired location even though I don't see it there.

Also, is there any workaround/patch for now? Or is everybody's leap and flit doing this?

alexandreroberts avatar Feb 26 '23 04:02 alexandreroberts

I have to do the next action while trusting that the cursor has jumped to the desired location even though I don't see it there.

the fake cursor should be visible though, if you don't see it, set Cursor: https://github.com/ggandor/leap.nvim/issues/27

Is there any update about when this issue will be fixed?

¯_(ツ)_/¯

Also, is there any workaround/patch for now? Or is everybody's leap and flit doing this?

Except for downgrading to Nvim 0.8, no there isn't.

ggandor avatar Feb 26 '23 11:02 ggandor

Thanks for sending me to the cursor hack! I put lua vim.api.nvim_set_hl(0, 'Cursor', { reverse = true }) in my init.vim, and now it is much better. Hopefully the hack will be obsolete soon...

alexandreroberts avatar Feb 26 '23 18:02 alexandreroberts

For anyone looking to apply the workaround suggested by @folke above, you can hook into LeapEnter and LeapLeave like so:

lua

vim.api.nvim_create_autocmd(
  "User",
  { callback = function()
      vim.cmd.hi("Cursor", "blend=100")
      vim.opt.guicursor:append { "a:Cursor/lCursor" }
    end,
    pattern = "LeapEnter"
  }
)
vim.api.nvim_create_autocmd(
  "User",
  { callback = function()
      vim.cmd.hi("Cursor", "blend=0")
      vim.opt.guicursor:remove { "a:Cursor/lCursor" }
    end,
    pattern = "LeapLeave"
  }
)

fennel

(vim.api.nvim_create_autocmd
  "User"
  { :callback
      (fn []
        (vim.cmd.hi "Cursor" "blend=100")
        (vim.opt.guicursor:append [ "a:Cursor/lCursor" ])
      )
    :pattern "LeapEnter"
  }
)
(vim.api.nvim_create_autocmd
  "User"
  { :callback
      (fn []
        (vim.cmd.hi "Cursor" "blend=0")
        (vim.opt.guicursor:remove [ "a:Cursor/lCursor" ])
      )
    :pattern "LeapLeave"
  }
)

vimscript

no

mitchellwrosen avatar Apr 25 '23 05:04 mitchellwrosen

This seems to work fine actually, I wasn't aware of the blend attribute. @mitchellwrosen care to make a PR? (To the end of main.fnl, after the other autocommands.)

ggandor avatar Apr 25 '23 11:04 ggandor

This may be fixed by https://github.com/neovim/neovim/pull/27858... removing the need for the fake cursor?!

theol0403 avatar Mar 15 '24 15:03 theol0403

removing the need for the fake cursor?!

As I understand, the fake cursor that Leap provides will be necessary even after this fix (the real cursor should appear on the command line when leaping), but at least we can get rid of the hide/show hack in our configs.

EDIT: No, it indeed seems to solve the fake cursor issue too. EDIT2: Only in Normal mode though, not in Visual. Interesting.

ggandor avatar Mar 15 '24 18:03 ggandor

Does Neovim 0.9.5 incorporate that fix? I am now getting rather strange behavior: sometimes f{ highlights the { as it should, and sometimes it does not, and I haven't been able to figure out what the pattern is. Even the exact same line responds differently to the exact same set of commands (e.g., 0f{). Perhaps it has to do with the context of other lines, such as whether the line is followed by a blank line? But I haven't been able to figure out what is determining the discrepancy.

alexandreroberts avatar Mar 18 '24 08:03 alexandreroberts

but at least we can get rid of the hide/show hack in our configs.

I'm not sure I have this hide/show hack active in my configuration anymore. Could I please ask what line of code you are referring to so I can search to see if I have it? (Sorry for my confusion about this.)

alexandreroberts avatar Mar 18 '24 08:03 alexandreroberts

Ah, is it this https://github.com/ggandor/leap.nvim?tab=readme-ov-file#bugs (and associated tweaks)?

alexandreroberts avatar Mar 18 '24 08:03 alexandreroberts

Does Neovim 0.9.5 incorporate that fix?

No.

Ah, is it this https://github.com/ggandor/leap.nvim?tab=readme-ov-file#bugs (and associated tweaks)?

Yes.

ggandor avatar Mar 18 '24 17:03 ggandor

Sorry for the stupid question, but if Neovim 0.9.5 doesn't incorporate the fix, how can I make use of the fix? Should I (as a non-sophisticated user) wait until it is incorporated into the next Neovim release? Or is it easy to update Neovim to this intermediate build?

alexandreroberts avatar Mar 18 '24 18:03 alexandreroberts

Well, the hack should work fine (does it?), so there's no hurry, but otherwise, yeah, you should wait for stable 0.10. Installing a pre-release version is totally straightforward though, just download from https://github.com/neovim/neovim/releases/tag/nightly, and follow the instructions for the given OS (same as for the stable release).

ggandor avatar Mar 19 '24 11:03 ggandor

The hack doesn't seem to work for me. I pasted the version from the Leap readme into .vim/plugin/leap.lua, but that did not seem to change anything when I started up a new instance of Neovim. When I looked at the two "tweaks" mentioned there, they didn't work for me either.

The hack here in #70 seems to be equivalent but with different formatting (e.g., uses " instead of ' at certain points). In any case, pasting that in instead did not fix the problem (neither for leap s nor for flit f).

#143 seems to be an implementation of that same hack that would seem to make it unnecessary for me to put anything into .vim/plugin/leap.lua at all.

Am I missing something? (Also, is the Neovim release coming out soon? As a novice user, I think I had better wait for a stable build, but if it's going to take a long time, it would be nice to fix this particular problem.)

alexandreroberts avatar Mar 19 '24 13:03 alexandreroberts

I think you should put the scripts in nvim/... instead of .vim/... (:help nvim-config).

ggandor avatar Mar 19 '24 13:03 ggandor

Ah, thank you! I have my .config/nvim/init.vim set to add .vim to the runtime path and to source my vimrc, but I had forgotten that in init.vim I had added an older one-line hack, which seems to have been interfering with the new hack. When I remove the old hack (but keep the new one in .vim), it seems to work!

For reference, the old hack that was interfering was:

" hack to make Leap work with current version of nvim (0.8.3). See
" https://github.com/ggandor/leap.nvim/issues/70
" and 
" https://github.com/ggandor/leap.nvim/issues/27#issuecomment-1445046929
lua vim.api.nvim_set_hl(0, 'Cursor', { reverse = true })

Thanks again!

alexandreroberts avatar Mar 19 '24 13:03 alexandreroberts

Oops, I wrote too soon. Now, oddly enough, leap and flit work only when the target is a bracket/brace. Other targets (e.g., letters) now behave the way the brackets/braces used to behave. How can I make it work for everything?

By the way, to make sure it wasn't a problem with where I put the hack, I have now moved it to nvim/init.lua, which reads:

-- Nvim-Tree documentation recommends disabling Netr at the very beginning of
-- the init.vim in order to avoid conflicts.
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

-- HACK from https://github.com/ggandor/leap.nvim?tab=readme-ov-file#bugs
-- to deal with the problem that the cursor disappears when jumping
-- to an open bracket.
-- Hide the (real) cursor when leaping, and restore it afterwards.
vim.api.nvim_create_autocmd('User', { pattern = 'LeapEnter',
    callback = function()
      vim.cmd.hi('Cursor', 'blend=100')
      vim.opt.guicursor:append { 'a:Cursor/lCursor' }
    end,
  }
)
vim.api.nvim_create_autocmd('User', { pattern = 'LeapLeave',
    callback = function()
      vim.cmd.hi('Cursor', 'blend=0')
      vim.opt.guicursor:remove { 'a:Cursor/lCursor' }
    end,
  }
)

-- use files in .vim
vim.cmd("set runtimepath^=~/.vim runtimepath+=~/.vim/after")
vim.cmd("let &packpath=&runtimepath")

-- use .vim/vimrc
vim.cmd("source ~/.vim/vimrc")

alexandreroberts avatar Mar 19 '24 14:03 alexandreroberts

It seems to me that in vscode there is still a duplicate cursor even when trying the workaround (I think I tried the one in the readme).

userrand avatar Mar 29 '24 08:03 userrand