aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRandy Palamar <palamar@ualberta.ca>2023-07-24 22:16:26 -0600
committerMatěj Cepl <mcepl@cepl.eu>2023-07-25 15:51:46 +0200
commit3112f23fd224d8ba9a09ed18756fd5cff8519946 (patch)
tree156ed806d7a5391188c8e5aa847e2a12ee81f558
parentf1f1ef2cb483f61c12e9627b8f85ae31d496fc1c (diff)
downloadvis-yank-highlight-master.tar.gz
implement the more useful normal mode highlightingHEADmaster
This makes use of vis's recursive mappings to call the highlighted-yank action after some logic to figure out if a complete selection was made. There isn't a good way of determing the end of the selection after entering OPERATOR_PENDING mode so we have to check after each keypress to determine if it can terminate a selection. Some keys might be missing but all the main ones should be there.
-rw-r--r--init.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index 142a5c8..fb9a80c 100644
--- a/init.lua
+++ b/init.lua
@@ -13,10 +13,25 @@ vis.events.subscribe(vis.events.INIT, function()
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