docs: small improvements to compl-autocomplete example (#25299)

- Don't complete when there is pending input.
- Use vim.list_contains() instead of vim.tbl_contains().
This commit is contained in:
zeertzjq
2023-09-22 06:51:47 +08:00
committed by GitHub
parent 6555176f34
commit fcfc87cb77

View File

@@ -1093,11 +1093,11 @@ To get basic "autocompletion" without installing a plugin, try this script: >lua
vim.api.nvim_create_autocmd("InsertCharPre", { vim.api.nvim_create_autocmd("InsertCharPre", {
buffer = vim.api.nvim_get_current_buf(), buffer = vim.api.nvim_get_current_buf(),
callback = function() callback = function()
if vim.fn.pumvisible() == 1 then if vim.fn.pumvisible() == 1 or vim.fn.state("m") == "m" then
return return
end end
local char = vim.v.char local char = vim.v.char
if vim.tbl_contains(triggers, char) then if vim.list_contains(triggers, char) then
local key = vim.keycode("<C-x><C-n>") local key = vim.keycode("<C-x><C-n>")
vim.api.nvim_feedkeys(key, "m", false) vim.api.nvim_feedkeys(key, "m", false)
end end