Last active
January 10, 2022 01:58
-
-
Save rockerBOO/6ff27c6052edc126a70c253e0fe170ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Thanks @tjdevries ! | |
-- neovim | |
-- Complete matching lines | |
-- See :help ins-completion | |
function CompleteMatchingLine() | |
local current_line = vim.api.nvim_get_current_line() | |
current_line = vim.trim(current_line) | |
if not current_line then | |
print("You aren't on a line or something weird") | |
return | |
end | |
local all_lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) | |
local matching_lines = {} | |
for _, v in ipairs(all_lines) do | |
if string.find(v, current_line, 1, true) then | |
table.insert(matching_lines, v) | |
end | |
end | |
vim.fn.complete(1, matching_lines) | |
return '' | |
end | |
vim.cmd [[inoremap <c-x><c-m> <c-r>=v:lua.CompleteMatchingLine()<CR>]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment