[vim/vim] autocomplete: how to get the first menu item selected (as if `<C-n>` was pressed then)? (Discussion #18340)

26 views
Skip to first unread message

Tomasz N

unread,
Sep 18, 2025, 5:06:35 PM (12 days ago) Sep 18
to vim/vim, Subscribed

Thanks to #18329 we have consistently selected no items resulted from autocomplete. I'm not sure if it's correct without noselect so ask here.

If so, is it possible to get the first menu item selected (as if <C-n> was pressed then)?

The below example is almost copied from #18326:

Let file /tmp/words consist of

v
vi
vim

  • run vim --clean -c 'se ac completeopt=menuone,noinsert,fuzzy' -c 'normal G' -c 'startinsert' /tmp/words
  • type v (no item selected)
image.png (view on web)

Expected result:
image.png (view on web)


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340@github.com>

girish

unread,
Sep 19, 2025, 2:55:55 AM (12 days ago) Sep 19
to vim/vim, Subscribed

It’s not entirely clear what you want. Are you asking to have the first item inserted automatically? That isn’t possible, since <BS> wouldn’t work in that case. However, you can enable preinsert, which will select the first item for you. This option doesn’t work as expected yet, but I plan to implement it soon.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14452189@github.com>

Tomasz N

unread,
Sep 19, 2025, 6:56:33 AM (12 days ago) Sep 19
to vim/vim, Subscribed

I would be interested with preinsert, but it does not work with fuzzy.

Currently we need to press <C-n> to get the first menu item active. I'd like to have it done automatically (and then get CompleteChanged event too).

It seems that we have no autocommand notifying when the menu is displayed.

The simple autocommand

au ModeChanged *:ic call feedkeys("\<C-n>")

seems to be not useful:

  • <C-n> may be entered too early, i.e. while acl is still pending
  • in other cases I get redundant (additional) <C-n>

I'm not sure if autoinserting <C-n> enough late would give me any useful result, but wanted to see what fails in such case.

Writing this comment I played with:

set autocomplete
set autocompletedelay=300
set completeopt=menuone,noinsert,fuzzy
set cpt+=k/usr/share/dict/american-english
au ModeChanged *:ic call feedkeys("\<C-n>")
startinsert


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14454830@github.com>

Tomasz N

unread,
Sep 19, 2025, 12:36:56 PM (11 days ago) Sep 19
to vim/vim, Subscribed

Forgive me for still being a bit confused about completeopt. If is true that autocomplete implicitly enables noselect (especially after making consistence in #18329), then maybe it is worth documentation.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14459150@github.com>

girish

unread,
Sep 28, 2025, 7:30:02 AM (3 days ago) Sep 28
to vim/vim, Subscribed

autocomplete automatically applies noselect unless you include preinsert.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14533675@github.com>

Tomasz N

unread,
Sep 28, 2025, 10:33:20 AM (2 days ago) Sep 28
to vim/vim, Subscribed

If I've missed something, it would be worth documenting.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14534442@github.com>

girish

unread,
Sep 28, 2025, 2:22:14 PM (2 days ago) Sep 28
to vim/vim, Subscribed

It is documented in :h cot in maybe not a clear way:

	Only "fuzzy", "popup", "popuphidden", "preinsert" and "preview" have
	an effect when 'autocomplete' is enabled.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14535447@github.com>

Tomasz N

unread,
Sep 29, 2025, 10:17:41 AM (yesterday) Sep 29
to vim/vim, Subscribed

There is no noselect 😉 Even if it were there, it would sound like an option that depends on being enabled manually, whereas, as you mentioned, currently it is forced by autocomplete (except with preinsert).


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14542789@github.com>

girish

unread,
Sep 29, 2025, 2:14:08 PM (yesterday) Sep 29
to vim/vim, Subscribed

Can you write a draft of enhanced help document? I think you have a point. I can review it and include it.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14544892@github.com>

Tomasz N

unread,
Sep 29, 2025, 2:39:22 PM (yesterday) Sep 29
to vim/vim, Subscribed

diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 748b5ae0..4b96f20b 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -2293,7 +2293,8 @@ A jump table for the options with a short description can be found at |Q_op|.

 	   noselect Same as "noinsert", except that no menu item is
 		    pre-selected.  If both "noinsert" and "noselect" are
-		    present, "noselect" has precedence.
+		    present, "noselect" has precedence. Forced when
+		    "preinsert" is not present, but 'autocomplete' is active.

 	   nosort   Disable sorting of completion candidates based on fuzzy
 		    scores when "fuzzy" is enabled.  Candidates will appear

What do you think?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14545088@github.com>

girish

unread,
9:09 AM (10 hours ago) 9:09 AM
to vim/vim, Subscribed

#18452


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/18340/comments/14552871@github.com>

Reply all
Reply to author
Forward
0 new messages