Documentation for modifying appearance of cmdline_popup dropdown #874
Replies: 1 comment 1 reply
-
To update - I was able to figure out how to get the width of the cmp popupmenu to stay a constant width following the bottom post in this thread. Actual config change in nvim-cmp: opts = {
format = function(entry, item)
if vim.tbl_contains({ "path" }, entry.source.name) then
local icon, hl_group = require("nvim-web-devicons").get_icon(entry:get_completion_item().label)
if icon then
item.kind = icon
item.kind_hl_group = hl_group
return item
end
end
if vim.tbl_contains({ "cmdline" }, entry.source.name) then
-- Get the completion entry text shown in the completion window.
local content = item.abbr
-- Set the fixed completion window width.
local fixed_width = 119
vim.o.pumwidth = fixed_width
-- Get the width of the current window.
local win_width = vim.api.nvim_win_get_width(0)
-- Set the max content width based on either: 'fixed_width'
-- or a percentage of the window width, in this case 20%.
-- We subtract 10 from 'fixed_width' to leave room for 'kind' fields.
local max_content_width = fixed_width and fixed_width - 10 or math.floor(win_width * 0.2)
-- Truncate the completion entry text if it's longer than the
-- max content width. We subtract 3 from the max content width
-- to account for the "..." that will be appended to it.
if #content > max_content_width then
item.abbr = vim.fn.strcharpart(content, 0, max_content_width - 3) .. "..."
else
item.abbr = content .. (" "):rep(max_content_width - #content)
end
end
return lspkind.cmp_format()(entry, item)
end,
-- Other configs ...
} With this, I'm sure I could get the top photo in my OP by just modifying the border properties of the cmp window for
For the second one, I'm sure I can check what you're doing in the source code for this repo and copy that approach. I'll try to find it and attempt once I get the time. For the first bullet, maybe this one is easy. Just starting to really learn lua after having to ditch Packer for lazy when I moved to nvim 0.10.0. I will do my best to dig into this and share the changes I had to make once I get it. Any guidance / wisdom you can share to point me in the right direction you might have would be immensely appreciated! 🙏 |
Beta Was this translation helpful? Give feedback.
-
Hello,
Maybe I'm posting in the wrong place, but there is a web of plugins and dependencies involved in what I'm trying to do. I know it also involves
telescope.nvim
and maybenvim-cmp
, but ultimately it tracks back to thecmdline_popup
configuration and associated results, so this project is the most sensible place to ask for help.I don't like how the dropdown / popupmenu / results (there are so many similar terms in the space, I am not even sure what term or setting I'm really looking for) resizes as I type, it's distracting. I'm trying to figure out how to get the results from the
cmdline_popup
to appear in a connected popup like the Code Actions do in the top photo fromtelescope-ui-select.nvim
. The results could even be detached like they are in the bottom photo - as long as they're the same width as thecmdline_popup
and appear underneath the input box:I've tried using
telescope-cmdline.nvim
, but it reverses the orientation and overrides many of the default behaviors I like about noice. I've spent days trying to figure out how to do this and looked at countless nvim configs without success, and am now caving writing this issue. It seems like this behavior is driven bynvim-cmp
maybe, but that the specific layout is some kind of telescope option, which just needs to be applied somewhere very, very specific.I would immensely appreciate any guidance you can give in helping me understand where I can control this config. If there's anything you need from me to assist, please let me know and I will be happy to provide it. Thanks for all you have contributed to the nvim community!
Beta Was this translation helpful? Give feedback.
All reactions