aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorMax Schillinger <maxschillinger@web.de>2024-03-18 10:08:40 +0100
committerRandy Palamar <randy@rnpnr.xyz>2025-11-28 07:41:12 -0700
commit3f1c3ee80e46f80d7f1642009c4f9dffa404d935 (patch)
tree08e3ab9011bcb4396ffca5f51d20c079d44da901 /lua
parent12fc09a442939d0af09d700c7a8074cca9b1694e (diff)
downloadvis-3f1c3ee80e46f80d7f1642009c4f9dffa404d935.tar.gz
vis-3f1c3ee80e46f80d7f1642009c4f9dffa404d935.tar.xz
Add command completion with tab key
In the command prompt, press <tab> to get a list of all available commands and pick one (using vis-menu). This works also after typing the first letters of a command (p.e. `:la<tab>`). Co-authored-by: Matěj Cepl <mcepl@cepl.eu>
Diffstat (limited to 'lua')
-rw-r--r--lua/plugins/complete-filename.lua18
1 files changed, 14 insertions, 4 deletions
diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua
index 604361c..db0f2a7 100644
--- a/lua/plugins/complete-filename.lua
+++ b/lua/plugins/complete-filename.lua
@@ -29,9 +29,19 @@ local complete_filename = function(expand)
prefix = home .. prefix:sub(j + 1)
end
- local cmdfmt = "vis-complete --file '%s'"
- if expand then cmdfmt = "vis-open -- '%s'*" end
- local status, out, err = vis:pipe(cmdfmt:format(prefix:gsub("'", "'\\''")))
+ local status, out, err
+ if prefix:sub(1, 1) == ":" then
+ status, out, err = vis:complete_command(prefix:sub(2))
+ if out then
+ out = out:gsub("\n$", ""):sub(#prefix) .. " "
+ end
+ pos = range.start + #prefix
+ expand = false
+ else
+ local cmdfmt = "vis-complete --file '%s'"
+ if expand then cmdfmt = "vis-open -- '%s'*" end
+ status, out, err = vis:pipe(cmdfmt:format(prefix:gsub("'", "'\\''")))
+ end
if status ~= 0 or not out then
if err then vis:info(err) end
return
@@ -55,4 +65,4 @@ end, "Complete file name")
-- complete file path at primary selection location using vis-open(1)
vis:map(vis.modes.INSERT, "<C-x><C-o>", function()
complete_filename(true);
-end, "Complete file name (expands path)")
+end, "Complete file name (expands path) or command")