Last active
March 27, 2025 01:46
-
-
Save xzbdmw/fb20eb84655b7c13b9e8aec760c992c0 to your computer and use it in GitHub Desktop.
Telescope dynamic height
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local root = vim.fn.fnamemodify("./.repro", ":p") | |
-- set stdpaths to use .repro | |
for _, name in ipairs({ "config", "data", "state", "cache" }) do | |
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name | |
end | |
-- bootstrap lazy | |
local lazypath = root .. "/plugins/lazy.nvim" | |
if not vim.loop.fs_stat(lazypath) then | |
vim.fn.system({ | |
"git", | |
"clone", | |
"--filter=blob:none", | |
"--single-branch", | |
"https://github.com/folke/lazy.nvim.git", | |
lazypath, | |
}) | |
end | |
_G.last = nil | |
local function on_complete(bo_line, bo_line_side, origin_height) | |
bo_line = "╰" .. string.rep("─", #bo_line - 2) .. "╯" | |
bo_line_side = "│" .. string.rep(" ", #bo_line_side - 2) .. "│" | |
vim.schedule(function() | |
local action_state = require("telescope.actions.state") | |
local prompt_bufnr = require("telescope.state").get_existing_prompt_bufnrs()[1] | |
local picker = action_state.get_current_picker(prompt_bufnr) | |
if picker == nil then | |
return | |
end | |
if not vim.api.nvim_buf_is_valid(picker.results_bufnr) then | |
return | |
end | |
local count = vim.api.nvim_buf_line_count(picker.results_bufnr) | |
local top_win = vim.api.nvim_win_get_config(picker.results_win) | |
local buttom_buf = vim.api.nvim_win_get_buf(picker.results_win + 1) | |
local bottom_win = vim.api.nvim_win_get_config(picker.results_win + 1) | |
top_win.height = math.max(count, 1) | |
top_win.height = math.min(top_win.height, origin_height) | |
bottom_win.height = math.max(count + 2, 3) | |
bottom_win.height = math.min(bottom_win.height, origin_height + 2) | |
vim.api.nvim_win_set_config(picker.results_win + 1, bottom_win) | |
vim.api.nvim_win_set_config(picker.results_win, top_win) | |
if _G.last ~= nil then | |
vim.api.nvim_buf_set_lines(buttom_buf, _G.last, _G.last + 1, false, { bo_line_side }) | |
end | |
vim.api.nvim_buf_set_lines(buttom_buf, math.max(count + 1, 2), math.max(count + 2, 3), false, { bo_line }) | |
_G.last = math.max(count + 1, 2) | |
end) | |
end | |
vim.opt.runtimepath:prepend(lazypath) | |
-- install plugins | |
local plugins = { | |
-- do not remove the colorscheme! | |
"folke/tokyonight.nvim", | |
{ | |
"nvim-telescope/telescope.nvim", | |
keys = { | |
{ | |
"<space>ff", | |
function() | |
require("telescope.builtin").find_files({ | |
on_complete = { | |
function() | |
on_complete(string.rep(" ", 60), string.rep(" ", 60), 18) | |
end, | |
}, | |
layout_strategy = "horizontal", | |
borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, | |
previewer = false, | |
sorting_strategy = "ascending", | |
layout_config = { | |
horizontal = { | |
width = 0.35, | |
height = 0.7, | |
}, | |
prompt_position = "top", | |
mirror = false, | |
}, | |
}) | |
end, | |
}, | |
}, | |
dependencies = { "nvim-lua/plenary.nvim" }, | |
config = function() | |
require("telescope").setup({}) | |
end, | |
}, | |
} | |
require("lazy").setup(plugins, { | |
root = root .. "/plugins", | |
}) | |
-- local- | |
vim.cmd([[colorscheme tokyonight]]) |
This is super cool! Any idea how to adjust the on_complete function for it to work with the ivy theme ?
Not sure, I would imagine you both cut the height and move the position of windows down
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What you need to adjust is this line
the first two argument should be the initial width of your picker, and last one is the initial height.
Run with
nvim -u ~/.config/nvim/repro.lua ~/.config/nvim/init.lua
to get a feel of it.iShot_2025-03-12_03.22.03.mp4