diff options
Diffstat (limited to 'lua/plugins/complete-word.lua')
| -rw-r--r-- | lua/plugins/complete-word.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lua/plugins/complete-word.lua b/lua/plugins/complete-word.lua new file mode 100644 index 0000000..68ce385 --- /dev/null +++ b/lua/plugins/complete-word.lua @@ -0,0 +1,22 @@ +-- complete word at primary cursor location using vis-complete(1) + +vis:map(vis.modes.INSERT, "<C-n>", 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 + if range.start == range.finish then return end + local prefix = file:content(range) + if not prefix then return end + local cmd = string.format("vis-complete --word '%s'", prefix:gsub("'", "'\\''")) + local status, out, err = vis:pipe(file, { start = 0, finish = file.size }, cmd) + if status ~= 0 or not out then + if err then vis:info(err) end + return + end + file:insert(pos, out) + win.cursor.pos = pos + #out +end, "Complete word in file") |
