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

The real cursor stays in its original position after autojumping #70

Closed
ggandor opened this issue Oct 22, 2022 · 19 comments
Closed

The real cursor stays in its original position after autojumping #70

ggandor opened this issue Oct 22, 2022 · 19 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ggandor
Copy link
Owner

ggandor commented Oct 22, 2022

ggandor/flit.nvim#3

@folke
Copy link

folke commented Oct 24, 2022

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.
folke/noice.nvim@42722b2

I hide the cursor whenever some plugin requests input :)

@ggandor ggandor changed the title The (real) cursor stays in its original position after autojumping The real cursor stays in its original position after autojumping Feb 22, 2023
@alexandreroberts
Copy link

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?

@ggandor
Copy link
Owner Author

ggandor commented Feb 26, 2023

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: #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.

@alexandreroberts
Copy link

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...

@mitchellwrosen
Copy link

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

@ggandor
Copy link
Owner Author

ggandor commented Apr 25, 2023

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.)

@theol0403
Copy link

This may be fixed by neovim/neovim#27858... removing the need for the fake cursor?!

@ggandor
Copy link
Owner Author

ggandor commented Mar 15, 2024

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.

@alexandreroberts
Copy link

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
Copy link

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
Copy link

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

@ggandor
Copy link
Owner Author

ggandor commented Mar 18, 2024

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 ggandor unpinned this issue Mar 18, 2024
@alexandreroberts
Copy link

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?

@ggandor
Copy link
Owner Author

ggandor commented Mar 19, 2024

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).

@alexandreroberts
Copy link

alexandreroberts commented Mar 19, 2024

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.)

@ggandor
Copy link
Owner Author

ggandor commented Mar 19, 2024

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

@alexandreroberts
Copy link

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
Copy link

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")

ggandor added a commit to ggandor/flit.nvim that referenced this issue Mar 20, 2024
@userrand
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants