Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to autocomplete your cursor's text on the first item too #1529

Closed
Thanatermesis opened this issue Apr 23, 2023 · 20 comments
Closed

option to autocomplete your cursor's text on the first item too #1529

Thanatermesis opened this issue Apr 23, 2023 · 20 comments

Comments

@Thanatermesis
Copy link

I have the "autocomplete = false", so menu only opens when I hit "tab"

If you see, when the second item is selected, the text in the cursor is filled up (similar to ghost_text), but this doesn't happens with the first item

In the normal behaviour that's somewhat normal, where the menu always opens with the first item preselected, but only when you scroll to the next option your cursor's text is modified, the issue is that the first item is not really preselected just hilighted, but when you trigger cmp.complete(), the first item should be selected in the same way the next ones are

@Thanatermesis Thanatermesis changed the title option to autocomplete the word on the first item option to autocomplete your cursor's text on the first item too Apr 23, 2023
@Shougo
Copy link

Shougo commented Apr 23, 2023

It seems dup of #1424

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 26, 2023

Sorry. I can't understand.

I guess you should check the following two points.

  1. The preselect option
    See :help cmp-faq

  2. Remove completeopt setting and set coompleteopt as vim option

set completeopt=menu,menuone,noselect

@hrsh7th hrsh7th closed this as completed Apr 26, 2023
@Thanatermesis
Copy link
Author

@hrsh7th tried but doesn't seems to work, I have recorded a video showing the issue: https://youtu.be/awc4BjLwf9M

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 27, 2023

What do you get the result with the followings?

  1. :echomsg &completeopt
  2. :imap <Tab>
  3. :lua= require('cmp').get_config()

@Shougo
Copy link

Shougo commented Apr 27, 2023

It seems Vim completeopt menu behavior(manual completion).
nvim-cmp default behavior is for auto completion.

@Thanatermesis
Copy link
Author

  1. menu,preview

  2. i * <Lua 480: ~/.local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:127>
    cmp.utils.keymap.set_map

  3. http://sprunge.us/bqzcZB

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 27, 2023

@Thanatermesis Could you try with :set completeopt=menu,menuone,noselect?

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 27, 2023

I can't determine the root cause. Sorry.

@Shougo
Copy link

Shougo commented Apr 27, 2023

@Thanatermesis You should create the minimal init.lua for it.

@uga-rosa
Copy link
Contributor

Is nvim-cmp updated to the latest version?
Also, please provide a stand alone init.lua that describes the minimal configuration necessary to reproduce this issue as @Shougo suggests. This is a good base to build on.

@Thanatermesis
Copy link
Author

@Thanatermesis Could you try with :set completeopt=menu,menuone,noselect?

Same issue, pressed Tab and the menu appears but my text is not replaced with the first result 🤔

Is nvim-cmp updated to the latest version?

Yes, I'm using the NvChad framework which already included nvim-cmp integrated, so maybe this can be an easy way to reproduce it (in a test environment, install NvChad in a single command, everything goes installed and nvim-cmp included, then change the trigger like "autocomplete = false" and add Tab to open the menu, just like in the video, and the bug should happen)

@Shougo
Copy link

Shougo commented Apr 27, 2023

Please don't use the plugin distribution for it.
It is not easy to reproduce for us.

@hrsh7th
Copy link
Owner

hrsh7th commented Apr 28, 2023

Could you try the following?

require('cmp').setup {
  completion = {
    completeopt = 'menu,menuone,noselect'
  }
}

My nvim-cmp config does not reproduce this problem so I think you should raise issue for the nvchad side.

@Thanatermesis
Copy link
Author

There's a small screencast of all the process (installing the nvim NvChad framework from zero, and without extra plugins) from scratch, the modifications I did to disable the autopopup, and showing the issue, including a "set" of the parameters you told me, in a strange way even if I set the values you said, it seems like when running nvim they are replaced by "menu,preview" 🤔

My nvim-cmp config does not reproduce this problem so I think you should raise issue for the nvchad side.

Maybe @siduck knows why the value of completeopt is replaced

Note: the bug is on the minute 5:00, already included on the link:

https://asciinema.org/a/IlDwksvQPFlq3qWY3emVwnMlF?t=4:58

@siduck
Copy link

siduck commented Apr 29, 2023

There's a small screencast of all the process (installing the nvim NvChad framework from zero, and without extra plugins) from scratch, the modifications I did to disable the autopopup, and showing the issue, including a "set" of the parameters you told me, in a strange way even if I set the values you said, it seems like when running nvim they are replaced by "menu,preview" thinking

My nvim-cmp config does not reproduce this problem so I think you should raise issue for the nvchad side.

Maybe @siduck knows why the value of completeopt is replaced

Note: the bug is on the minute 5:00, already included on the link:

https://asciinema.org/a/IlDwksvQPFlq3qWY3emVwnMlF?t=4:58

image

just override nvim-cmp opts in your custom plugins

@Thanatermesis
Copy link
Author

@siduck yes that's what I do but it doesn't seems to take effect, I changed it to "menu,menuone,noselect" but it doesn't gets static (as you can see in the video), on the other hand I set it manually with :set to that value but the bug stills present 🤔

@siduck
Copy link

siduck commented Apr 29, 2023

works here tho

simplescreenrecorder-2023-04-29_06.27.25.mp4

@Thanatermesis

{
    "hrsh7th/nvim-cmp",
    opts = {
      completion = {
        completeopt = "menu,menuone,noselect",
      },
    },
},

@Thanatermesis
Copy link
Author

@siduck Mmmh, I don't think so, the issue is that when the menu is set to not automatically popup all the time but with manually triggering it, so by pressing tab, the text is not autocompleted to the first result, only to the next ones

This means, adding "autocomplete = false," on the completion section, and in the TAB mapping, changing the fallback line to "cmp.complete()"

More details on the first post and a demo on the video: https://youtu.be/awc4BjLwf9M

@Thanatermesis
Copy link
Author

Ok so I think this code made it finally working, so first I need to have the entry to completeopt = "menu,menuone,noselect", otherwise without "noselect", the first selection will be made (without filling up my code with it, so what is this issue about),

Then, I need to replace the cmp.complete() entry (which is triggered with Tab) using this combination instead, which If im not wrong what it does is "create the menu" and "switch to the first item"

        cmp.complete({ behavior = cmp.SelectBehavior.Select })
        cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })

This looks very good! the menu only appears when I press Tab, at the same time my text has the added keyword, if I press "space" the keyword is kept (used) on my line, if i want to open a snippet I press "enter"... same behaviour with the menu automatically showing up (which is annoying for me at the moment because it doesn't lets me to use Copilot as I mentioned here)

@srcrip
Copy link

srcrip commented Jun 17, 2024

For anyone coming across this from google, you can improve it a little bit more by conditionally running complete based on whether the menu is already open. heres the full example I'm using right now:

          ["<C-k>"] = cmp.mapping(function(fallback)
            if not cmp.visible() then
              cmp.complete({ behavior = cmp.SelectBehavior.Select })
            end
            cmp.select_prev_item({ behavior = cmp.SelectBehavior.Insert })
          end, { 'i', 's' }),
          ["<C-j>"] = cmp.mapping(function(fallback)
            if not cmp.visible() then
              cmp.complete({ behavior = cmp.SelectBehavior.Select })
            end
            cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })
          end, { 'i', 's' }),

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

No branches or pull requests

6 participants