Skip to content

feat: make 'preinsert' work with 'autocomplete'#18213

Closed
girishji wants to merge 4 commits intovim:masterfrom
girishji:preinsert
Closed

feat: make 'preinsert' work with 'autocomplete'#18213
girishji wants to merge 4 commits intovim:masterfrom
girishji:preinsert

Conversation

@girishji
Copy link
Contributor

@girishji girishji commented Sep 5, 2025

This change extends Insert mode autocompletion so that "preinsert" behavior of 'completeopt' also
works when 'autocomplete' is enabled. The behavior is slightly different.

Try: :set autocomplete completeopt=preinsert. It's quite useful.

See :help 'cot' for more details.

Also, added example setup for autocomplete. See :h ins-autocompletion-example.

@habamax
Copy link
Contributor

habamax commented Sep 6, 2025

Looks like hl-ComplMatchIns is not defined in vim/colorschemes. Is it a new one or I completely overlooked its existence?

image

@girishji
Copy link
Contributor Author

girishji commented Sep 6, 2025

I think you overlooked. It was already there. I just noticed it was undefined, so I linked it to the Added highlight group.

@chrisbra
Copy link
Member

chrisbra commented Sep 6, 2025

Thanks, but this seems to break a few screen-dump tests

@girishji
Copy link
Contributor Author

girishji commented Sep 6, 2025

Thanks, but this seems to break a few screen-dump tests

Thanks, just noticed this. The failures are caused by the highlight group ComplMatchIns, which I had linked incorrectly to another group. ComplMatchIns isn’t limited to preinsert -- it also highlights the postfix part of the text when selecting from the popup menu.

I am not sure if it would make sense to have a separate highlight group for preinsert. For now, I reverted the changes.

@habamax I think hl-ComplMatchIns can’t really be used in any colorscheme, because it highlights a portion of every match you pick from the menu. That feels quite unusual.

This change extends Insert mode autocompletion so that 'preinsert' also
works when 'autocomplete' is enabled.

Try: `:set ac cot=preinsert`

See `:help 'cot'` for more details.
Added a new highlight group since preinsert is a different function than what
hl-ComplMatchIns serves.
@girishji
Copy link
Contributor Author

girishji commented Sep 7, 2025

Added a new highlight group hl-PreInsert. Using hl-ComplMatchIns for both purposes prevented setting distinct default colors for pre-inserted text. Currently applies only to 'autocomplete'.

M  src/edit.c
M  src/insexpand.c
M  runtime/doc/insert.txt
@chrisbra
Copy link
Member

chrisbra commented Sep 8, 2025

thanks

@chrisbra chrisbra closed this in fa6fd41 Sep 8, 2025
@girishji
Copy link
Contributor Author

girishji commented Sep 8, 2025

Thanks

@girishji girishji deleted the preinsert branch September 8, 2025 19:53
@habamax
Copy link
Contributor

habamax commented Sep 8, 2025

@lifepillar, there is new PreInsert hl, you may want to add it to coloremplate.

image

zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Sep 9, 2025
…sert

Problem:  complete: preinsert does not work well with preinsert
Solution: Make "preinsert" completeopt value work with autocompletion
          (Girish Palya)

This change extends Insert mode autocompletion so that 'preinsert' also
works when 'autocomplete' is enabled.

Try: `:set ac cot=preinsert`

See `:help 'cot'` for more details.

closes: vim/vim#18213

vim/vim@fa6fd41

Co-authored-by: Girish Palya <girishji@gmail.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Sep 9, 2025
…sert

Problem:  complete: preinsert does not work well with preinsert
Solution: Make "preinsert" completeopt value work with autocompletion
          (Girish Palya)

This change extends Insert mode autocompletion so that 'preinsert' also
works when 'autocomplete' is enabled.

Try: `:set ac cot=preinsert`

See `:help 'cot'` for more details.

closes: vim/vim#18213

vim/vim@fa6fd41

Co-authored-by: Girish Palya <girishji@gmail.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Sep 9, 2025
…sert

Problem:  complete: preinsert does not work well with preinsert
Solution: Make "preinsert" completeopt value work with autocompletion
          (Girish Palya)

This change extends Insert mode autocompletion so that 'preinsert' also
works when 'autocomplete' is enabled.

Try: `:set ac cot=preinsert`

See `:help 'cot'` for more details.

closes: vim/vim#18213

vim/vim@fa6fd41

Co-authored-by: Girish Palya <girishji@gmail.com>
zeertzjq added a commit to neovim/neovim that referenced this pull request Sep 9, 2025
…complete' (#35692)

Problem:  complete: preinsert does not work well with preinsert
Solution: Make "preinsert" completeopt value work with autocompletion
          (Girish Palya)

This change extends Insert mode autocompletion so that 'preinsert' also
works when 'autocomplete' is enabled.

Try: `:set ac cot=preinsert`

See `:help 'cot'` for more details.

closes: vim/vim#18213

vim/vim@fa6fd41

Co-authored-by: Girish Palya <girishji@gmail.com>
@justinmk
Copy link
Contributor

justinmk commented Sep 9, 2025

Added a new highlight group hl-PreInsert. Using hl-ComplMatchIns

Why is the new hl group named PreInsert, instead of something like ComplPreIns ? Can Vim please pick a convention and stick with it?

@chrisbra
Copy link
Member

chrisbra commented Sep 9, 2025

It should be ComplMatchPreIns no? We can rename it

@girishji
Copy link
Contributor Author

girishji commented Sep 9, 2025

I wasn’t aware there was a convention. I chose what felt the most intuitive and readable. When I first saw hl-ComplMatchIns, it looked like a jumble of letters I couldn’t immediately connect to anything. If a convention is already established, I don’t mind following it, but it feels odd to replace a meaningful tag with something that looks cryptic.

@habamax
Copy link
Contributor

habamax commented Sep 9, 2025

There seems to be no convention. I personally like PreInsert more.

@habamax
Copy link
Contributor

habamax commented Sep 9, 2025

@chrisbra do you go to neovim github questioning what neovim does?

The message could have been a tiny bit more polite.

girishji added a commit to girishji/vim that referenced this pull request Sep 9, 2025
Broken by vim#18213
Fixed now.

M  src/insexpand.c
M  src/testdir/test_ins_complete.vim
girishji added a commit to girishji/vim that referenced this pull request Sep 9, 2025
When `"preinsert"` is included in `'completeopt'`, only the `hl-PreInsert`
highlight group should be applied, whether autocompletion is active or not.
Previously, `hl-ComplMatchIns` was used when autocompletion was not enabled.

Related to vim#18213.
@chrisbra
Copy link
Member

chrisbra commented Sep 9, 2025

The message could have been a tiny bit more polite.

agree.

if a convention is already established, I don’t mind following it, but it feels odd to replace a meaningful tag with something that looks cryptic.

Well, we only have a single highlight group for completion: ComplMatchIns so it seems we have a precedent for other related highlighting groups. So if there is a chance we will have more additional related highlighting groups related to completion feature, I think this would make sense to have a consistent naming.

@girishji
Copy link
Contributor Author

girishji commented Sep 9, 2025

The doc is incorrect:

ComplMatchIns   Matched text of the currently inserted completion.

This highlight group applies to the unmatched portion of the completion (the suffix). Consider renaming it to something like InsertedSuffix, CompletionSuffix, PostfixText, etc. Current name conveys the opposite meaning of what it is doing, if it conveys any meaning at all.

@chrisbra
Copy link
Member

So this comes from patch 6a38aff (v9.1.0936). We could consider renaming it. But I think this is too late already

@habamax
Copy link
Contributor

habamax commented Sep 10, 2025

According to the document you have recently authored, it is not too late :)

FWIW, it is not in any of built-in colorschemes.

@chrisbra
Copy link
Member

yep I know. in that case what would be a good naming convention? Something that would also apply for PreInsert?

@habamax
Copy link
Contributor

habamax commented Sep 10, 2025

in that case what would be a good naming convention? Something that would also apply for PreInsert?

Should we have a prefix for the group of 2 (as of now) highlight groups?

  • CompletePreInsert, CoPreInsert, CtePreInsert, ...
  • CompleteMatchInsert, CoMatchInsert, CteMatchInsert, ... or CompleteSuffix, CompleteMatchSuffix, CoMatchSuffix, CteMatchSuffix

chrisbra pushed a commit that referenced this pull request Sep 10, 2025
…tchIns

Problem:  completion: preinserted text highlighed using ComplMatchIns
Solution: Use highlighting group PreInsert and update the documentation
          (Girish Palya).

When "preinsert" is included in 'completeopt', only the PreInsert
highlight group should be applied, whether autocompletion is active or not.
Previously, ComplMatchIns was used when autocompletion was not enabled.

Related to #18213.

closes: #18254

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
@Shane-XB-Qian

This comment was marked as off-topic.

zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Sep 10, 2025
…plMatchIns

Problem:  completion: preinserted text highlighed using ComplMatchIns
Solution: Use highlighting group PreInsert and update the documentation
          (Girish Palya).

When "preinsert" is included in 'completeopt', only the PreInsert
highlight group should be applied, whether autocompletion is active or not.
Previously, ComplMatchIns was used when autocompletion was not enabled.

Related to vim/vim#18213.

closes: vim/vim#18254

vim/vim@2525c56

Co-authored-by: Girish Palya <girishji@gmail.com>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Sep 10, 2025
…plMatchIns

Problem:  completion: preinserted text highlighed using ComplMatchIns
Solution: Use highlighting group PreInsert and update the documentation
          (Girish Palya).

When "preinsert" is included in 'completeopt', only the PreInsert
highlight group should be applied, whether autocompletion is active or not.
Previously, ComplMatchIns was used when autocompletion was not enabled.

Related to vim/vim#18213.

closes: vim/vim#18254

vim/vim@2525c56

Co-authored-by: Girish Palya <girishji@gmail.com>
dundargoc pushed a commit to dundargoc/neovim that referenced this pull request Sep 27, 2025
…complete' (neovim#35692)

Problem:  complete: preinsert does not work well with preinsert
Solution: Make "preinsert" completeopt value work with autocompletion
          (Girish Palya)

This change extends Insert mode autocompletion so that 'preinsert' also
works when 'autocomplete' is enabled.

Try: `:set ac cot=preinsert`

See `:help 'cot'` for more details.

closes: vim/vim#18213

vim/vim@fa6fd41

Co-authored-by: Girish Palya <girishji@gmail.com>
dundargoc pushed a commit to dundargoc/neovim that referenced this pull request Sep 27, 2025
…plMatchIns

Problem:  completion: preinserted text highlighed using ComplMatchIns
Solution: Use highlighting group PreInsert and update the documentation
          (Girish Palya).

When "preinsert" is included in 'completeopt', only the PreInsert
highlight group should be applied, whether autocompletion is active or not.
Previously, ComplMatchIns was used when autocompletion was not enabled.

Related to vim/vim#18213.

closes: vim/vim#18254

vim/vim@2525c56

Co-authored-by: Girish Palya <girishji@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants