replit / codemirror-vim

Vim keybindings for CM6
https://www.npmjs.com/package/@replit/codemirror-vim
MIT License
289 stars 30 forks source link

[feature request] add highlight to the yanked region #121

Open aleksey-rowan opened 1 year ago

aleksey-rowan commented 1 year ago

Please add an option to highlight the yanked region like in https://github.com/machakann/vim-highlightedyank or natively in Neovim. Thanks!

nightwing commented 1 year ago

@sergeichestakov should we add this feature, or should we limit the scope to vim defaults only?

sergeichestakov commented 1 year ago

yeah I think we'll want to stick with defaults as close as possible. we can possibly add it as a config option tho

aleksey-rowan commented 1 year ago

yeah I think we'll want to stick with defaults as close as possible. we can possibly add it as a config option tho

I understand the importance to sticking with the defaults and avoiding scope creep, but if this can be added an an option, that would be amazing. Highlighting yanks is one of those quality-of-life features--I believe--that almost everyone adds to their configs right away.

Thank you for considering this anyway!

joelostblom commented 1 year ago

This is actually available as a default in Neovim, and it is super helpful. Especially for confirming the yanked region (especially when grabbing a paragraph or targeting a character where it is easy to overlook that there is another of the same character earlier or grab an extra whitespace), and also for teaching/presenting so that others can easily follow along what you are doing. I raised this in the jupyterlab-vim repo originally https://github.com/jupyterlab-contrib/jupyterlab-vim/issues/117 and posted this example:

aleksey-rowan commented 9 months ago

Shameless plug here. I made an Obsidian plugin to do just that--highlight the yanked region. If you are using Obsidian and were missing that feature, check it out:

https://github.com/aleksey-rowan/obsidian-vim-yank-highlight

joelostblom commented 9 months ago

That's great, thank you @aleksey-rowan ! Is there anything from your approach that would be useful/able to be transferred over if this feature is approved to be added in codemirror directly? Or is it completely different to implement it in obsidian?

aleksey-rowan commented 9 months ago

@joelostblom, there is almost nothing Obsidian-specific apart from the plugin wrapper, so I think the same approach can be added to the codemirror-vim directly. It should be even easier since you can hook into the pushTest/yank handler instead of listening to key events and then trying to find yanked text in the viewport.

There is another Obsidian yank plugin that does a similar thing by monkey-patching codemirror-vim, so their approach would be even more adaptable to be bundled in.