commit | cbe53191d01926c045a39198b3a9517e3c5077d2 | [log] [tgz] |
---|---|---|
author | Girish Palya <girishji@gmail.com> | Mon Apr 14 22:13:15 2025 +0200 |
committer | Christian Brabandt <cb@256bit.org> | Mon Apr 14 22:13:15 2025 +0200 |
tree | 94d68db50465b3a99024111fc1f2d185b4ce32a7 | |
parent | 10f69298b4577b3712eedeb49b4d9ad1a69111f8 [diff] |
patch 9.1.1301: completion: cannot configure completion functions with 'complete' Problem: completion: cannot configure completion functions with 'complete' Solution: add support for setting completion functions using the f and o flag for 'complete' (Girish Palya) This change adds two new values to the `'complete'` (`'cpt'`) option: - `f` – invokes the function specified by the `'completefunc'` option - `f{func}` – invokes a specific function `{func}` (can be a string or `Funcref`) These new flags extend keyword completion behavior (e.g., via `<C-N>` / `<C-P>`) by allowing function-based sources to participate in standard keyword completion. **Key behaviors:** - Multiple `f{func}` values can be specified, and all will be called in order. - Functions should follow the interface defined in `:help complete-functions`. - When using `f{func}`, escaping is required for spaces (with `\`) and commas (with `\\`) in `Funcref` names. - If a function sets `'refresh'` to `'always'`, it will be re-invoked on every change to the input text. Otherwise, Vim will attempt to reuse and filter existing matches as the input changes, which matches the default behavior of other completion sources. - Matches are inserted at the keyword boundary for consistency with other completion methods. - If finding matches is time-consuming, `complete_check()` can be used to maintain responsiveness. - Completion matches are gathered in the sequence defined by the `'cpt'` option, preserving source priority. This feature increases flexibility of standard completion mechanism and may reduce the need for external completion plugins for many users. **Examples:** Complete matches from [LSP](https://github.com/yegappan/lsp) client. Notice the use of `refresh: always` and `function()`. ```vim set cpt+=ffunction("g:LspCompletor"\\,\ [5]). # maxitems = 5 def! g:LspCompletor(maxitems: number, findstart: number, base: string): any if findstart == 1 return g:LspOmniFunc(findstart, base) endif return {words: g:LspOmniFunc(findstart, base)->slice(0, maxitems), refresh: 'always'} enddef autocmd VimEnter * g:LspOptionsSet({ autoComplete: false, omniComplete: true }) ``` Complete matches from `:iabbrev`. ```vim set cpt+=fAbbrevCompletor def! g:AbbrevCompletor(findstart: number, base: string): any if findstart > 0 var prefix = getline('.')->strpart(0, col('.') - 1)->matchstr('\S\+$') if prefix->empty() return -2 endif return col('.') - prefix->len() - 1 endif var lines = execute('ia', 'silent!') if lines =~? gettext('No abbreviation found') return v:none # Suppresses warning message endif var items = [] for line in lines->split("\n") var m = line->matchlist('\v^i\s+\zs(\S+)\s+(.*)$') if m->len() > 2 && m[1]->stridx(base) == 0 items->add({ word: m[1], info: m[2], dup: 1 }) endif endfor return items->empty() ? v:none : items->sort((v1, v2) => v1.word < v2.word ? -1 : v1.word ==# v2.word ? 0 : 1) enddef ``` **Auto-completion:** Vim's standard completion frequently checks for user input while searching for new matches. It is responsive irrespective of file size. This makes it well-suited for smooth auto-completion. You can try with above examples: ```vim set cot=menuone,popup,noselect inf autocmd TextChangedI * InsComplete() def InsComplete() if getcharstr(1) == '' && getline('.')->strpart(0, col('.') - 1) =~ '\k$' SkipTextChangedIEvent() feedkeys("\<c-n>", "n") endif enddef inoremap <silent> <c-e> <c-r>=<SID>SkipTextChangedIEvent()<cr><c-e> def SkipTextChangedIEvent(): string # Suppress next event caused by <c-e> (or <c-n> when no matches found) set eventignore+=TextChangedI timer_start(1, (_) => { set eventignore-=TextChangedI }) return '' enddef ``` closes: #17065 Co-authored-by: Christian Brabandt <cb@256bit.org> Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: glepnir <glephunter@gmail.com> Signed-off-by: Girish Palya <girishji@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
If you find a bug or want to discuss the best way to add a new feature, please open an issue. If you have a question or want to discuss the best way to do something with Vim, you can use StackExchange or one of the Maillists.
Vim is a greatly improved version of the good old UNIX editor Vi. Many new features have been added: multi-level undo, syntax highlighting, command line history, on-line help, spell checking, filename completion, block operations, script language, etc. There is also a Graphical User Interface (GUI) available. Still, Vi compatibility is maintained, those who have Vi "in the fingers" will feel at home. See runtime/doc/vi_diff.txt
for differences with Vi.
This editor is very useful for editing programs and other plain text files. All commands are given with normal keyboard characters, so those who can type with ten fingers can work very fast. Additionally, function keys can be mapped to commands by the user, and the mouse can be used.
Vim runs under MS-Windows (7, 8, 10, 11), macOS, Haiku, VMS and almost all flavours of UNIX. Porting to other systems should not be very difficult. Older versions of Vim run on MS-DOS, MS-Windows 95/98/Me/NT/2000/XP/Vista, Amiga DOS, Atari MiNT, BeOS, RISC OS and OS/2. These are no longer maintained.
For Vim9 script see README_VIM9.
You can often use your favorite package manager to install Vim. On Mac and Linux a small version of Vim is pre-installed, you still need to install Vim if you want more features.
There are separate distributions for Unix, PC, Amiga and some other systems. This README.md
file comes with the runtime archive. It includes the documentation, syntax files and other files that are used at runtime. To run Vim you must get either one of the binary archives or a source archive. Which one you need depends on the system you want to run it on and whether you want or must compile it yourself. Check https://www.vim.org/download.php for an overview of currently available distributions.
Some popular places to get the latest Vim:
If you obtained a binary distribution you don't need to compile Vim. If you obtained a source distribution, all the stuff for compiling Vim is in the src
directory. See src/INSTALL
for instructions.
See one of these files for system-specific instructions. Either in the READMEdir directory (in the repository) or the top directory (if you unpack an archive):
README_ami.txt Amiga README_unix.txt Unix README_dos.txt MS-DOS and MS-Windows README_mac.txt Macintosh README_haiku.txt Haiku README_vms.txt VMS
There are other README_*.txt
files, depending on the distribution you used.
The Vim tutor is a one hour training course for beginners. Often it can be started as vimtutor
. See :help tutor
for more information.
The best is to use :help
in Vim. If you don't have an executable yet, read runtime/doc/help.txt
. It contains pointers to the other documentation files. The User Manual reads like a book and is recommended to learn to use Vim. See :help user-manual
.
Vim is Charityware. You can use and copy it as much as you like, but you are encouraged to make a donation to help orphans in Uganda. Please read the file runtime/doc/uganda.txt
for details (do :help uganda
inside Vim).
Summary of the license: There are no restrictions on using or distributing an unmodified copy of Vim. Parts of Vim may also be distributed, but the license text must always be included. For modified versions, a few restrictions apply. The license is GPL compatible, you may compile Vim with GPL libraries and distribute it.
Fixing bugs and adding new features takes a lot of time and effort. To show your appreciation for the work and motivate developers to continue working on Vim please send a donation.
The money you donated will be mainly used to help children in Uganda. See runtime/doc/uganda.txt
. But at the same time donations increase the development team motivation to keep working on Vim!
For the most recent information about sponsoring look on the Vim web site: https://www.vim.org/sponsor/
If you would like to help make Vim better, see the CONTRIBUTING.md file.
If you are on macOS, you can use MacVim.
The latest news about Vim can be found on the Vim home page: https://www.vim.org/
If you have problems, have a look at the Vim documentation or tips: https://www.vim.org/docs.php https://vim.fandom.com/wiki/Vim_Tips_Wiki
If you still have problems or any other questions, use one of the mailing lists to discuss them with Vim users and developers: https://www.vim.org/maillist.php
If nothing else works, report bugs directly to the vim-dev mailing list: <vim-dev@vim.org>
Most of Vim was created by Bram Moolenaar <Bram@vim.org>
Bram-Moolenaar
Send any other comments, patches, flowers and suggestions to the vim-dev mailing list: <vim-dev@vim.org>
This is README.md
for version 9.1 of Vim: Vi IMproved.