Skip to content

Commit

Permalink
feat(nvim): resize telescope window in sync with terminal columns
Browse files Browse the repository at this point in the history
  • Loading branch information
kutsan committed Nov 18, 2024
1 parent 6f986e5 commit 7c57daf
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion .config/nvim/lua/specs/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ Plugin.dependencies = {
{ 'debugloop/telescope-undo.nvim', name = 'telescope-undo' },
}

local function get_telescope_width()
local term_width = vim.o.columns
return term_width <= 100 and 0.9 or 0.65
end

Plugin.opts = function()
local actions = require('telescope.actions')

local term_width = vim.o.columns
local width = term_width <= 100 and 0.9 or 0.65

return {
defaults = {
prompt_title = '',
Expand All @@ -31,7 +39,7 @@ Plugin.opts = function()
vertical = {
prompt_position = 'top',
preview_cutoff = 10,
width = 0.65,
width = get_telescope_width(),
mirror = true,
},
},
Expand All @@ -55,6 +63,25 @@ Plugin.config = function(_, opts)
telescope.load_extension('git_worktree')
telescope.load_extension('undo')

-- Resize telescope window when the terminal is resized.
vim.api.nvim_create_autocmd('VimResized', {
group = vim.api.nvim_create_augroup(
'TelescopeAdjustWidth',
{ clear = true }
),
callback = function()
telescope.setup({
defaults = {
layout_config = {
vertical = {
width = get_telescope_width(),
},
},
},
})
end,
})

local keymap = vim.keymap
local map_opts = { silent = true }

Expand Down

0 comments on commit 7c57daf

Please sign in to comment.