Files
neovim/runtime/doc/news.txt
zeertzjq 1de276bbcd vim-patch:9.1.1308: completion: cannot order matches by distance to cursor (#33491)
Problem:  During insert-mode completion, the most relevant match is often
          the one closest to the cursor—frequently just above the current line.
          However, both `<C-N>` and `<C-P>` tend to rank candidates from the
          current buffer that appear above the cursor near the bottom of the
          completion menu, rather than near the top. This ordering can feel
          unintuitive, especially when `noselect` is active, as it doesn't
          prioritize the most contextually relevant suggestions.

Solution: This change introduces a new sub-option value "nearest" for the
          'completeopt' setting. When enabled, matches from the current buffer
          are prioritized based on their proximity to the cursor position,
          improving the relevance of suggestions during completion
          (Girish Palya).

Key Details:
- Option: "nearest" added to 'completeopt'
- Applies to: Matches from the current buffer only
- Effect: Sorts completion candidates by their distance from the cursor
- Interaction with other options:
  - Has no effect if the `fuzzy` option is also present

This feature is helpful especially when working within large buffers where
multiple similar matches may exist at different locations.

You can test this feature with auto-completion using the snippet below. Try it
in a large file like `vim/src/insexpand.c`, where you'll encounter many
potential matches. You'll notice that the popup menu now typically surfaces the
most relevant matches—those closest to the cursor—at the top. Sorting by
spatial proximity (i.e., contextual relevance) often produces more useful
matches than sorting purely by lexical distance ("fuzzy").

Another way to sort matches is by recency, using an LRU (Least Recently Used)
cache—essentially ranking candidates based on how recently they were used.
However, this is often overkill in practice, as spatial proximity (as provided
by the "nearest" option) is usually sufficient to surface the most relevant
matches.

```vim
set cot=menuone,popup,noselect,nearest inf

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

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>

inoremap <silent><expr> <tab>   pumvisible() ? "\<c-n>" : "\<tab>"
inoremap <silent><expr> <s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"
```

closes: vim/vim#17076

b156588eb7

Co-authored-by: Girish Palya <girishji@gmail.com>
2025-04-16 02:48:08 +00:00

206 lines
4.0 KiB
Plaintext

*news.txt* Nvim
NVIM REFERENCE MANUAL
Notable changes since Nvim 0.11 *news*
For changes in the previous release, see |news-0.11|.
Type |gO| to see the table of contents.
==============================================================================
BREAKING CHANGES IN HEAD OR EXPERIMENTAL *news-breaking-dev*
====== Remove this section before release. ======
The following changes to UNRELEASED features were made during the development
cycle (Nvim HEAD, the "master" branch).
EXPERIMENTS
• todo
LSP
• todo
OPTIONS
• todo
TREESITTER
• todo
==============================================================================
BREAKING CHANGES *news-breaking*
These changes may require adaptations in your config or plugins.
API
• todo
BUILD
• todo
DIAGNOSTICS
• |diagnostic-signs| can no longer be configured with |:sign-define| or
|sign_define()| (deprecated in Nvim 0.10 |deprecated-0.10|).
• |vim.diagnostic.disable()| and |vim.diagnostic.is_disabled()| (deprecated in
Nvim 0.10 |deprecated-0.10|) are removed.
• The legacy signature of |vim.diagnostic.enable()| (deprecated in Nvim 0.10
|deprecated-0.10|) is no longer supported.
EDITOR
• todo
EVENTS
• todo
HIGHLIGHTS
• todo
LSP
• todo
LUA
• todo
OPTIONS
• 'chistory' and 'lhistory' set size of the |quickfix-stack|.
• 'completeopt' flag "nearset" sorts completion results by distance to cursor.
• 'diffopt' `inline:` configures diff highlighting for changes within a line.
• 'pummaxwidth' sets maximum width for the completion popup menu.
• 'shelltemp' defaults to "false".
PLUGINS
• todo
TREESITTER
• todo
TUI
• todo
VIMSCRIPT
• todo
==============================================================================
NEW FEATURES *news-features*
The following new features were added.
API
• |vim.hl.range()| now allows multiple timed highlights
DEFAULTS
• todo
DIAGNOSTICS
• todo
EDITOR
• |:iput| works like |:put| but adjusts indent.
• |omnicompletion| in `help` buffer. |ft-help-omni|
EVENTS
• todo
HIGHLIGHTS
• |hl-DiffTextAdd| highlights added text within a changed line.
LSP
• |vim.lsp.ClientConfig| gained `workspace_required`.
LUA
• Lua type annotations for `vim.uv`.
OPTIONS
• 'autowriteall' writes all buffers upon receiving `SIGHUP`, `SIGQUIT` or `SIGTSTP`.
• 'completefuzzycollect' enables fuzzy collection of candidates for (some)
|ins-completion| modes.
• 'diffopt' `inline:` configures diff highlighting for changes within a line.
• 'pummaxwidth' sets maximum width for the completion popup menu.
• 'winborder' "bold" style.
• |g:clipboard| accepts a string name to force any builtin clipboard tool.
PERFORMANCE
• todo
PLUGINS
• todo
STARTUP
• todo
TERMINAL
• todo
TREESITTER
• todo
TUI
• todo
UI
• |:checkhealth| shows a summary in the header for every healthcheck.
• |ui-multigrid| provides composition information and absolute coordinates.
VIMSCRIPT
• todo
==============================================================================
CHANGED FEATURES *news-changed*
These existing features changed their behavior.
• 'spellfile' location defaults to `stdpath("data").."/spell/"` instead of the
first writable directoy in 'runtimepath'.
• |vim.version.range()| doesn't exclude `to` if it is equal to `from`.
==============================================================================
REMOVED FEATURES *news-removed*
These deprecated features were removed.
• todo
==============================================================================
DEPRECATIONS *news-deprecations*
See |deprecated-0.12|.
vim:tw=78:ts=8:sw=2:et:ft=help:norl: