[mini.completion] Autoimport on a keymap using ctrl-n and ctrl-y with noselect #1767
-
Contributing guidelines
Module(s)mini.completion Questionlocal keycode = vim.keycode or function(x) return vim.api.nvim_replace_termcodes(x, true, true, true) end
local keys = {
["ctrl-k"] = keycode("<C-k>"), -- enter digraph, the default
["ctrl-y"] = keycode("<C-y>"), -- confirm selected item
["ctrl-n_ctrl-y"] = keycode("<C-n><C-y>"), -- no selection by user, confirm first item
}
---@diagnostic disable-next-line: duplicate-set-field
_G.confirm_action = function()
if vim.fn.pumvisible() ~= 0 then
local item_selected = vim.fn.complete_info()["selected"] ~= -1
return item_selected and keys["ctrl-y"] or keys["ctrl-n_ctrl-y"]
else
return keys["ctrl-k"] -- enter digraph
end
end
-- Prefer typing c-k over c-y to accept completion
vim.keymap.set("i", "<C-k>", "v:lua._G.confirm_action()", { expr = true })
The code above is working with It's also working with // rust...
fn main() {
println!("Hello, world!");
}
struct Dog<Breed> {
name: String,
}
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Yes, this seems to be a result of this caveat as With 'noinsert' the item is selected immediately and for the long enough duration (longer than With 'noselect' the item is selected only for a very-very brief moment of time before being accepted (all due to This all seems to work as expected. Does this answer the question (as there is no explicit one, I am not sure)? |
Beta Was this translation helpful? Give feedback.
By making sure that this caveat is taken care of. I.e. instead of
keycode("<C-n><C-y>")
mimic pressing<C-n>
, wait for a bit, mimic pressing<C-y>
. Things that can make this more usable are:config.delay.info
.additionalTextEdits
. It is a bit tricky and relies on implementation detail of complete-item having original LSP item aslsp.item
in complete-item'suser_data
field. Thevim.fn.complete_info()
can be used to get the first matched complet…