Closed ghost closed 11 months ago
vis
is truly minimalist: the tarball has 395k, so I believe plugin would be a way preferable. Try to port that VimScript to Lua and we can then discuss whether it would be included as a permanent plugin into the official repo.
Personally I don't think its useful since I can't really imagine a situation where I wouldn't know what I'm yanking. However here is something I came up with if anyone wants it:
vis.events.subscribe(vis.events.INIT, function()
local yank = vis:action_register("highlighted-yank", function()
vis.win:style_define(vis.win.STYLE_SELECTION, "reverse")
vis:redraw()
local tstamp = os.clock()
while os.clock() - tstamp < 0.5 do end
vis.win:style_define(vis.win.STYLE_SELECTION, vis.lexers.STYLE_SELECTION)
vis:redraw()
end, "Yank operator with highlighting")
vis:map(vis.modes.OPERATOR_PENDING, "y", yank)
vis:map(vis.modes.VISUAL, "y", yank)
vis:map(vis.modes.VISUAL_LINE, "y", yank)
end)
Note: you also need to highlight the selected range in OPERATOR_PENDING
to obtain the same result as the vim plugin. It shouldn't be that
difficult to do.
It is actually rather convenient. With some weird combination of selection object, I am often not completely certain that I have copied exactly what I wanted.
Anyway, I have created https://git.sr.ht/~mcepl/vis-yank-highlight added
require('plugins/vis-yank-highlight')
to my ~/.config/vis/visrc.lua
and nothing happens. When I run for example y$
, text is correctly copied, but no highlighting happens.
That is what I mean by:
Note: you also need to highlight the selected range in
OPERATOR_PENDING
Right now it only works in the especially useless case where the selection is already highlighted. Since you want to use it as a plugin I will see what I can do about adding that functionality. I'll email a patch if I figure it out.
With https://lists.sr.ht/~mcepl/devel/patches/42973 applied and working, could we say that the plugin could work as a proof of concept and the evidence we can close this ticket as irrelevant for the vis itself?
Yes I think that is appropriate. There may be some limits to the plugin as I wrote it but I'll leave it up to anyone who wants to use it to address them. I think its a pretty good start.
In the vein of https://github.com/machakann/vim-highlightedyank or Neovim's
highlight.on_yank()
. It's really very nice, and in my opinion small enough that it should really be part of the editor and not a plugin.