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

Fix the width of completion menu #980

Open
2 tasks done
krishnakumarg1984 opened this issue May 9, 2022 · 11 comments
Open
2 tasks done

Fix the width of completion menu #980

krishnakumarg1984 opened this issue May 9, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@krishnakumarg1984
Copy link

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Issues

  • I have checked existing issues and there are no open or closed issues with the same problem.

Neovim Version

0.7

Minimal reproducible full config

cmp.nvim's autocompletion pop-up menu changes width to accommodate the completion candidates.

While, there are a few options to set the max_width, I don't see any solution to fix the pop-up menu at a certain width.
Can we have an option in cmp to set the pop-up menu to a fixed width?

Description

It is rather annoying when the completion menu's width keeps on changing to be bigger and smaller, leading to a very jarring user experience.

Steps to reproduce

Default config of cmp.

Expected behavior

Fix the pop-up window width irrespective of the length of the completion candidates.

Actual behavior

The completion menu's width keeps on changing to be bigger and smaller dynamically, depending on the width of the populated candidates.

Additional context

The constantly changing pop-up menu width is rather annoying and leads to a jarring user experience.

@krishnakumarg1984 krishnakumarg1984 added the bug Something isn't working label May 9, 2022
@gegoune
Copy link
Contributor

gegoune commented May 9, 2022

#609 (comment) Is that solution good enough?

@krishnakumarg1984
Copy link
Author

No. As I mentioned in my comments to that question. The solution in #609 (comment) only helps to truncate items to a maximum width.

It doesn't help to eliminate the jarring visual effects of changing pop-up width during completion.

@Shougo
Copy link

Shougo commented May 10, 2022

No. As I mentioned in my comments to that question. The solution in #609 (comment) only helps to truncate items to a maximum width.

I think you can define minimum width in format function.

@krishnakumarg1984
Copy link
Author

@Shougo Nice. Can you show us how?

@Shougo
Copy link

Shougo commented May 10, 2022

  local ELLIPSIS_CHAR = ''
  local MAX_LABEL_WIDTH = 20
  local MIN_LABEL_WIDTH = 20

  cmp.setup({
    formatting = {
      format = function(entry, vim_item)
        local label = vim_item.abbr
        local truncated_label = vim.fn.strcharpart(label, 0, MAX_LABEL_WIDTH)
        if truncated_label ~= label then
          vim_item.abbr = truncated_label .. ELLIPSIS_CHAR
        elseif string.len(label) < MIN_LABEL_WIDTH then
          local padding = string.rep(' ', MIN_LABEL_WIDTH - string.len(label))
          vim_item.abbr = label .. padding
        end
        return vim_item
      end,
    },
  })

@krishnakumarg1984
Copy link
Author

@Shougo Awesome. Thank works! Thank you so much!

@kevinhughes27
Copy link

kevinhughes27 commented May 26, 2022

It looks like the menu still saves space for the menu/kind even when fields is set to only abbr. This solution only fixes the width of the abbr field as far as I can tell when I tried it. I'm using only the abbr field for cmdline completion where the other fields are not useful. It would be great to remove this extra space!

Update - I can achieve what I want by setting kind and menu to empty string:

format = function(_, vim_item)
    vim_item.menu = ""
    vim_item.kind = ""
    return vim_item
end

@askfiy
Copy link
Contributor

askfiy commented Jun 18, 2022

Wish he had built in

@krishnakumarg1984
Copy link
Author

@hrsh7th Can we please have a cmp menu with overall fixed width, as well as a fixed width for the description field?

@nullptr-yxw
Copy link

Wish he had built in

As was mentioned in #1535, It might be possible to set the minimum width and maximum height by options pumwidth and pumheight, but they are global settings. So I will push a new issue about it

@gmr458
Copy link

gmr458 commented Jan 9, 2024

It looks like the menu still saves space for the menu/kind even when fields is set to only abbr. This solution only fixes the width of the abbr field as far as I can tell when I tried it. I'm using only the abbr field for cmdline completion where the other fields are not useful. It would be great to remove this extra space!

Update - I can achieve what I want by setting kind and menu to empty string:

format = function(_, vim_item)
    vim_item.menu = ""
    vim_item.kind = ""
    return vim_item
end

this is working for me, I only use kind and abbr so I set vim_item.menu = ''

iovis added a commit to iovis/dotfiles that referenced this issue Feb 12, 2024
Should probably add some media queries and/or toggles, but it's a start

Relevant issue: hrsh7th/nvim-cmp#980
notfirefox added a commit to notfirefox/nvim-config that referenced this issue Aug 3, 2024
Restrict the width of the completion window by omitting the `menu` item
from the `fields` table of the `formatting`. Additionally we have
overridden the `format` function of the `formatting` section [1,2].

[1] hrsh7th/nvim-cmp#980 (comment)
[2] hrsh7th/nvim-cmp#890
notfirefox added a commit to notfirefox/nvim-config that referenced this issue Aug 3, 2024
Restrict the width of the completion window by omitting the `menu` item
from the `fields` table of the `formatting`. Clear the `menu` string
in the `format` function of the `formatting` section [1,2].

[1] hrsh7th/nvim-cmp#980 (comment)
[2] hrsh7th/nvim-cmp#890
notfirefox added a commit to notfirefox/nvim-config that referenced this issue Aug 3, 2024
Restrict the width of the completion window by omitting the `menu` item
from the `fields` table of the `formatting`. Clear the `menu` string
in the `format` function of the `formatting` section [1,2].

[1] hrsh7th/nvim-cmp#980 (comment)
[2] hrsh7th/nvim-cmp#890
jdhao added a commit to jdhao/nvim-config that referenced this issue Aug 19, 2024
1. restrict max width of the completion menu. Here I am using
   lspkind.nvim to achieve this. There are other native ways to do this,
   see also hrsh7th/nvim-cmp#609 and
   hrsh7th/nvim-cmp#980
2. remove cmp-emoji as it is rarely used and interfere when I write
   Python
3. lower the transparency for popup menu
jdhao added a commit to jdhao/nvim-config that referenced this issue Aug 19, 2024
1. restrict max width of the completion menu. Here I am using
   lspkind.nvim to achieve this. There are other native ways to do this,
   see also hrsh7th/nvim-cmp#609 and
   hrsh7th/nvim-cmp#980
2. remove cmp-emoji as it is rarely used and interfere when I write
   Python
3. lower the transparency for popup menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants