0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

runtime(doc): clarify how to call complete() funcs

related: #18287

Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt
2025-09-15 20:21:38 +00:00
parent 8801c9db2e
commit f79e262ffc

View File

@@ -1,4 +1,4 @@
*builtin.txt* For Vim version 9.1. Last change: 2025 Sep 08 *builtin.txt* For Vim version 9.1. Last change: 2025 Sep 15
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1913,10 +1913,11 @@ col({expr} [, {winid}]) *col()*
complete({startcol}, {matches}) *complete()* *E785* complete({startcol}, {matches}) *complete()* *E785*
Set the matches for Insert mode completion. Set the matches for Insert mode completion. Can only be
Can only be used in Insert mode. You need to use a mapping used in Insert mode. Typically invoked from a mapping with
with CTRL-R = (see |i_CTRL-R|). It does not work after CTRL-O CTRL-R = (see |i_CTRL-R|), but may also be called from a
or with an expression mapping. |<Cmd>| or |<ScriptCmd>| mapping. It does not work after
CTRL-O or with an expression mapping.
{startcol} is the byte offset in the line where the completed {startcol} is the byte offset in the line where the completed
text start. The text up to the cursor is the original text text start. The text up to the cursor is the original text
that will be replaced by the matches. Use col('.') for an that will be replaced by the matches. Use col('.') for an
@@ -1930,15 +1931,31 @@ complete({startcol}, {matches}) *complete()* *E785*
The match can be selected with CTRL-N and CTRL-P as usual with The match can be selected with CTRL-N and CTRL-P as usual with
Insert mode completion. The popup menu will appear if Insert mode completion. The popup menu will appear if
specified, see |ins-completion-menu|. specified, see |ins-completion-menu|.
Example: >
inoremap <F5> <C-R>=ListMonths()<CR>
func ListMonths() Example (using legacy Vim script): >
call complete(col('.'), ['January', 'February', 'March',
\ 'April', 'May', 'June', 'July', 'August', 'September', inoremap <F5> <C-R>=ListMonths()<CR>
\ 'October', 'November', 'December'])
return '' func ListMonths()
endfunc call complete(col('.'), ['January', 'February', 'March',
\ 'April', 'May', 'June', 'July', 'August',
\ 'September', \ 'October', 'November', 'December'])
return ''
endfunc
<
Example (using Vim9 script): >
vim9script
def ListMonths(): string
const months = [ 'January', 'February', 'March', 'April',
'May', 'June', 'July', 'September', 'October',
'November', 'December']
complete(col('.'), months)
return ''
enddef
inoremap <F5> <ScriptCmd>ListMonths()<CR>
< This isn't very useful, but it shows how it works. Note that < This isn't very useful, but it shows how it works. Note that
an empty string is returned to avoid a zero being inserted. an empty string is returned to avoid a zero being inserted.