From 7b9c063d116064bb0765c76277fe210c7ac01d0c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 27 Sep 2025 09:09:03 +0800 Subject: vim-patch:9.1.1797: completion: autocompletion can be improved Problem: completion: autocompletion can be improved Solution: Add support for "longest" and "preinsert" in 'autocomplete'; add preinserted() (Girish Palya) * Add support for "longest" in 'completeopt' when 'autocomplete' is enabled. (Note: the cursor position does not change automatically when 'autocomplete' is enabled.) * Add support for "preinsert" when 'autocomplete' is enabled. Ensure "preinsert" works the same with and without 'autocomplete' * introduce the preinserted() Vim script function, useful for defining custom key mappings. fixes: vim/vim#18314 closes: vim/vim#18387 https://github.com/vim/vim/commit/c05335082adb21d99d96374779856444a3a0688f Co-authored-by: Girish Palya --- runtime/lua/vim/_meta/vimfn.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime/lua/vim/_meta/vimfn.lua') diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua index 4302c3d689..4b50b90f65 100644 --- a/runtime/lua/vim/_meta/vimfn.lua +++ b/runtime/lua/vim/_meta/vimfn.lua @@ -6554,6 +6554,14 @@ function vim.fn.perleval(expr) end --- @return number function vim.fn.pow(x, y) end +--- Returns non-zero if text has been inserted after the cursor +--- because "preinsert" is present in 'completeopt', or if +--- "longest" is present in 'completeopt' while 'autocomplete' +--- is enabled. Otherwise returns zero. +--- +--- @return number +function vim.fn.preinserted() end + --- Return the line number of the first line at or above {lnum} --- that is not blank. Example: >vim --- let ind = indent(prevnonblank(v:lnum - 1)) -- cgit