Shrink the UI when there are few options and/or preview is not available #2274
Answered
by
nenahp
proxima1998
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
nenahp
Aug 25, 2025
Replies: 1 comment 7 replies
-
I custom my own, it's not hard: require('fzf-lua').setup { 'hide' }
vim.ui.select = function(ui_items, ui_opts, ui_on_choice)
ui_on_choice = ui_on_choice or function() end
ui_opts = ui_opts or {}
local opts = ui_opts.fzf_lua_opts or {}
local contents
local title = ('[%s]'):format(ui_opts.prompt or 'Select')
local default = {
winopts = function()
return {
relative = 'cursor',
title = title,
row = 0.5,
height = not opts.preview and math.min(math.max(#ui_items + 1, 2), 20) or nil,
}
end,
query = ui_opts.default,
actions = {
['enter'] = {
fn = function(sel)
local n = #sel
if n == 0 then
ui_on_choice(nil, nil)
return
end
local idx = vim.iter(sel):map(function(v) return v + 1 end):totable()
local item = vim.iter(idx):map(function(v) return ui_items[v] end):totable()
if n <= 1 then
item, idx = item[1], idx[1]
end
ui_on_choice(item, idx)
end,
field_index = '{+n}', -- field_index only work in "hide" profile (or we use exec_silent = true)
exec_silent = ui_opts.no_close,
},
},
}
contents = vim.is_callable(ui_opts.format_item)
and vim.iter(ui_items):map(ui_opts.format_item):totable()
or ui_items
require('fzf-lua').set_info { mod = 'ui', cmd = 'select', fnc = 'ui.select' }
require('fzf-lua.core').fzf_exec(contents, vim.tbl_deep_extend('force', default, opts))
end |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
proxima1998
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I custom my own, it's not hard: