Completing word causes vis to exit insert mode, since we changed
complete-words to use vis' regex in 004800e348cba1bf5f4536876b4e0eafbcf1ea58.
Simply remember the current mode and restore it after the completion.
---
lua/plugins/complete-word.lua | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lua/plugins/complete-word.lua b/lua/plugins/complete-word.lua
index 78127514..f330e598 100644
--- a/lua/plugins/complete-word.lua+++ b/lua/plugins/complete-word.lua
@@ -13,6 +13,8 @@ vis:map(vis.modes.INSERT, "<C-n>", function()
local prefix = file:content(range)
if not prefix then return end
+ local mode = vis.mode+ vis:feedkeys("<vis-selections-save><Escape><Escape>")
-- collect words starting with prefix
vis:command("x/\\b" .. prefix .. "\\w+/")
@@ -33,4 +35,5 @@ vis:map(vis.modes.INSERT, "<C-n>", function()
out = out:sub(#prefix + 1, #out - 1)
file:insert(pos, out)
win.selection.pos = pos + #out
+ vis.mode = modeend, "Complete word in file")
--
2.44.0
Florian Fischer <florian.fischer@muhq.space> wrote:
> Completing word causes vis to exit insert mode, since we changed> complete-words to use vis' regex in 004800e348cba1bf5f4536876b4e0eafbcf1ea58.> > Simply remember the current mode and restore it after the completion.> ---> lua/plugins/complete-word.lua | 3 +++> 1 file changed, 3 insertions(+)> > diff --git a/lua/plugins/complete-word.lua b/lua/plugins/complete-word.lua> index 78127514..f330e598 100644> --- a/lua/plugins/complete-word.lua> +++ b/lua/plugins/complete-word.lua> @@ -13,6 +13,8 @@ vis:map(vis.modes.INSERT, "<C-n>", function()> local prefix = file:content(range)> if not prefix then return end> > + local mode = vis.mode> +> vis:feedkeys("<vis-selections-save><Escape><Escape>")> -- collect words starting with prefix> vis:command("x/\\b" .. prefix .. "\\w+/")> @@ -33,4 +35,5 @@ vis:map(vis.modes.INSERT, "<C-n>", function()> out = out:sub(#prefix + 1, #out - 1)> file:insert(pos, out)> win.selection.pos = pos + #out> + vis.mode = mode> end, "Complete word in file")
Hi Florian,
Thanks for the patch; I guess I forgot to commit the fix when I
noticed this earlier. I will go with just explicitly setting mode
back to INSERT on exit since this keybinding is only valid in INSERT
mode.
- Randy
--
https://rnpnr.xyz/
GPG Fingerprint: B8F0 CF4C B6E9 415C 1B27 A8C4 C8D2 F782 86DF 2DC5