summaryrefslogtreecommitdiff
path: root/config/essentials/vis/yank-highlight.lua
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-22 02:05:44 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-22 02:05:44 +0200
commit36d2972c60ec86b873fa496d1f5ea95cf748cf49 (patch)
treea6d6750fa17c2964cd241afa8e963cac6106b390 /config/essentials/vis/yank-highlight.lua
parent4914b43f642e2772a140a8f9b1f26b4e555ed88b (diff)
parent32256e087aaf7744348a5ba33e802d5c8d9d97dd (diff)
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'config/essentials/vis/yank-highlight.lua')
-rw-r--r--config/essentials/vis/yank-highlight.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/config/essentials/vis/yank-highlight.lua b/config/essentials/vis/yank-highlight.lua
new file mode 100644
index 0000000..37a9578
--- /dev/null
+++ b/config/essentials/vis/yank-highlight.lua
@@ -0,0 +1,37 @@
+require("vis")
+
+local M = {
+ style = "reverse", -- Style used for highlighting
+ duration = 0.2, -- [s] Time to remain highlighted (10 ms precision)
+}
+
+vis.events.subscribe(vis.events.INIT, function()
+ local yank = vis:action_register("highlighted-yank", function()
+ vis.win:style_define(vis.win.STYLE_SELECTION, M.style)
+ vis:redraw()
+ local tstamp = os.clock()
+ while os.clock() - tstamp < M.duration do end
+ vis.win:style_define(vis.win.STYLE_SELECTION, vis.lexers.STYLE_SELECTION)
+ vis:redraw()
+ vis:feedkeys("<vis-operator-yank>")
+ 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)
+
+ vis:map(vis.modes.NORMAL, "y", function(keys)
+ local sel_end_chrs = "$%^{}()wp"
+ if #keys < 1 or sel_end_chrs:find(keys:sub(-1), 1, true) == nil then
+ if keys:find("<Escape>") then
+ return #keys
+ end
+ return -1
+ end
+ vis:feedkeys("<vis-mode-visual-charwise>")
+ vis:feedkeys(keys)
+ vis:feedkeys("y<Escape>")
+ return #keys
+ end)
+end)
+
+return M