Skip to content

Commit

Permalink
Make telescope theme change depending on screen size
Browse files Browse the repository at this point in the history
  • Loading branch information
Icelk committed Jul 5, 2023
1 parent 415d2d1 commit a252e1c
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions config/nvim/lua/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,39 @@ vim.o.foldexpr = "nvim_treesitter#foldexpr()"
local telescope = require "telescope"
local telescope_actions = require "telescope.actions"
local tele_builtin = require "telescope.builtin"
-- local tele_theme = require "telescope.themes".get_ivy()
local tele_theme = nil
local tele_theme_dropdown = require "telescope.themes".get_dropdown()
local tele_theme_cursor = require "telescope.themes".get_cursor()
local tele_theme_default = nil

function dynamic_theme()
local width = vim.api.nvim_win_get_width(0)
local height = vim.api.nvim_win_get_height(0)

if width / 2 > height then
return tele_theme_default
else
return tele_theme_dropdown
end
end
local theme = dynamic_theme


telescope.setup { defaults = { mappings = { i = { ["<esc>"] = telescope_actions.close } } } }

-- Telescope for nvim UI
require "dressing".setup { select = { telescope = tele_theme } }
require "dressing".setup { select = { telescope = tele_theme_cursor } }

nmap("<C-p>", function() tele_builtin.find_files(tele_theme) end)
nmap("<C-g>", function() tele_builtin.oldfiles(tele_theme) end)
nmap("<C-A-p>", function() tele_builtin.grep_string(tele_theme) end)
nmap("S", function() tele_builtin.spell_suggest(tele_theme) end)
nmap("<C-p>", function() tele_builtin.find_files(theme()) end)
nmap("<C-g>", function() tele_builtin.oldfiles(theme()) end)
nmap("<C-e>", function() tele_builtin.treesitter(theme()) end)
nmap("<C-A-p>", function() tele_builtin.grep_string(theme()) end)
nmap("S", function() tele_builtin.spell_suggest(theme()) end)
nmap("<C-/>", function() tele_builtin.current_buffer_fuzzy_find(theme()) end)

nmap("<space>a", function() tele_builtin.diagnostics(tele_theme) end)
nmap("<space>b", function() tele_builtin.buffers(tele_theme) end)
nmap("<space>c", function() tele_builtin.git_bcommits(tele_theme) end)
nmap("<space>g", function() tele_builtin.git_stash(tele_theme) end)
nmap("<space>a", function() tele_builtin.diagnostics(theme()) end)
nmap("<space>b", function() tele_builtin.buffers(theme()) end)
nmap("<space>c", function() tele_builtin.git_bcommits(theme()) end)
nmap("<space>g", function() tele_builtin.git_stash(theme()) end)


require('nvim_comment').setup({ create_mappings = true, line_mapping = "<leader>cc", operator_mapping = "<leader>c" })
Expand Down Expand Up @@ -168,10 +184,10 @@ local on_attach = function(client, bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr }

-- Remap keys for gotos
nmapo("gd", function() tele_builtin.lsp_definitions(tele_theme) end, opts)
nmapo("gy", function() tele_builtin.lsp_type_definitions(tele_theme) end, opts)
nmapo("gi", function() tele_builtin.lsp_implementations(tele_theme) end, opts)
nmapo("gr", function() tele_builtin.lsp_references(tele_theme) end, opts)
nmapo("gd", function() tele_builtin.lsp_definitions(theme()) end, opts)
nmapo("gy", function() tele_builtin.lsp_type_definitions(theme()) end, opts)
nmapo("gi", function() tele_builtin.lsp_implementations(theme()) end, opts)
nmapo("gr", function() tele_builtin.lsp_references(theme()) end, opts)
nmapo('gD', vim.lsp.buf.declaration, opts)
-- nmapo('<C-k>', vim.lsp.buf.signature_help, bufopts)

Expand Down Expand Up @@ -204,8 +220,8 @@ local on_attach = function(client, bufnr)

nvmapo("<leader>f", function() vim.lsp.buf.code_action(nil, nil, true) end);

nmapo("<space>o", function() tele_builtin.lsp_dynamic_workspace_symbols(tele_theme) end, opts)
nmapo("<space>s", function() tele_builtin.lsp_document_symbols(tele_theme) end, opts)
nmapo("<space>o", function() tele_builtin.lsp_dynamic_workspace_symbols(theme()) end, opts)
nmapo("<space>s", function() tele_builtin.lsp_document_symbols(theme()) end, opts)
end


Expand Down

0 comments on commit a252e1c

Please sign in to comment.