codemirror-vim icon indicating copy to clipboard operation
codemirror-vim copied to clipboard

[feature request] add highlight to the yanked region

Open aleksey-rowan opened this issue 2 years ago • 7 comments

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

aleksey-rowan avatar Apr 30 '23 20:04 aleksey-rowan

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

nightwing avatar May 01 '23 13:05 nightwing

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

sergeichestakov avatar May 01 '23 13:05 sergeichestakov

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!

aleksey-rowan avatar May 01 '23 14:05 aleksey-rowan

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:

joelostblom avatar Oct 02 '23 21:10 joelostblom

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

aleksey-rowan avatar Dec 19 '23 02:12 aleksey-rowan

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?

joelostblom avatar Dec 19 '23 15:12 joelostblom

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

aleksey-rowan avatar Dec 19 '23 18:12 aleksey-rowan