aboutsummaryrefslogtreecommitdiff
path: root/lua/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'lua/plugins')
-rw-r--r--lua/plugins/complete-filename.lua31
1 files changed, 30 insertions, 1 deletions
diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua
index 824e33a..3648efe 100644
--- a/lua/plugins/complete-filename.lua
+++ b/lua/plugins/complete-filename.lua
@@ -1,4 +1,4 @@
--- complete file name at primary cursor location using vis-complete(1)
+-- complete file path at primary cursor location using vis-complete(1)
vis:map(vis.modes.INSERT, "<C-x><C-f>", function()
local win = vis.win
@@ -20,4 +20,33 @@ vis:map(vis.modes.INSERT, "<C-x><C-f>", function()
end
file:insert(pos, out)
win.cursor.pos = pos + #out
+end, "Complete file path")
+
+-- complete file path at primary cursor location using vis-open(1)
+
+vis:map(vis.modes.INSERT, "<C-x><C-o>", function()
+ local win = vis.win
+ local file = win.file
+ local pos = win.cursor.pos
+ if not pos then return end
+ local range = file:text_object_word(pos > 0 and pos-1 or pos);
+ if not range then return end
+ if range.finish > pos then range.finish = pos end
+ local prefix = file:content(range)
+ if not prefix then return end
+ if prefix:match("^%s*$") then
+ prefix = ""
+ range.start = pos
+ range.finish = pos
+ end
+ local cmd = string.format("vis-open -- '%s'*", prefix:gsub("'", "'\\''"))
+ local status, out, err = vis:pipe(file, { start = 0, finish = 0 }, cmd)
+ if status ~= 0 or not out then
+ if err then vis:info(err) end
+ return
+ end
+ out = out:gsub("\n$", "")
+ file:delete(range)
+ file:insert(range.start, out)
+ win.cursor.pos = range.start + #out
end, "Complete file name")