nvim: clean up telescope config

This commit is contained in:
Daniel Lundin 2022-09-10 12:08:37 +02:00
parent 7c56115cc9
commit 688587e9ab
3 changed files with 83 additions and 83 deletions

View file

@ -1,60 +0,0 @@
local telescope = require("telescope")
local actions = require("telescope.actions")
local previewers = require("telescope.previewers")
-- Setup
telescope.setup {
defaults = {
layout_strategy = "flex",
-- layout_defaults = {flip_columns = 160},
layout_config = {
preview_cutoff = 10,
},
mappings = {
i = {
["<CR>"] = actions.select_default + actions.center,
["<esc>"] = actions.close,
["<tab>"] = actions.add_selection
}
},
color_devicons = true,
file_previewer = previewers.vim_buffer_cat.new,
grep_previewer = previewers.vim_buffer_vimgrep.new,
qflist_previewer = previewers.vim_buffer_qflist.new
}
}
local layout_strategies = require("telescope.pickers.layout_strategies")
local config = require("telescope.config")
layout_strategies.flex = function(self, max_columns, max_lines)
local layout_config = self.layout_config or {}
local flip_columns = layout_config.flip_columns or 160 -- Here's why.
local flip_lines = layout_config.flip_lines or 20
if max_columns < flip_columns and max_lines > flip_lines then
self.layout_config = (config.values.layout_defaults or {})["vertical"]
return layout_strategies.vertical(self, max_columns, max_lines)
else
self.layout_config = (config.values.layout_defaults or {})["horizontal"]
return layout_strategies.horizontal(self, max_columns, max_lines)
end
end
-- Extensions
telescope.load_extension("dap")
telescope.load_extension("fzy_native")
telescope.load_extension("gh")
-- telescope.load_extension("packer") -- currently breaking packer
local M = {}
-- Pickers
M.project_files = function()
require("telescope.builtin").find_files {
cwd = require("lspconfig.util").root_pattern(".git")(vim.fn.expand("%:p"))
}
end
return M

View file

@ -151,29 +151,7 @@ return require("packer").startup(function()
"nvim-telescope/telescope-dap.nvim",
},
config = function()
require("dln.telescope")
local map = require("dln.utils").map
map("n", "<leader>b", '<cmd>lua require("telescope.builtin").buffers()<CR>')
map("n", "<leader>f", '<cmd>lua require("telescope.builtin").oldfiles()<CR>')
map("n", "<space>", '<cmd>lua require("telescope.builtin").oldfiles()<CR>')
map("n", "<leader>e", '<cmd>lua require("telescope.builtin").git_files()<CR>')
map("n", "<leader>g", '<cmd>lua require("telescope.builtin").git_status()<CR>')
map("n", "<leader>a", '<cmd>lua require("telescope.builtin").lsp_code_actions()<CR>')
map("n", "<leader>m", '<cmd>lua require("telescope.builtin").marks()<CR>')
map("n", "<leader>s", '<cmd>lua require("telescope.builtin").lsp_document_symbols()<CR>')
map("n", "<leader>t", '<cmd>lua require("telescope.builtin").treesitter()<CR>')
map("n", "<leader>/", '<cmd>lua require("telescope.builtin").live_grep()<CR>')
map("n", "<leader>.", '<cmd>lua require("telescope.builtin").file_browser()<CR>')
map("n", "<leader>p", '<cmd>lua require("telescope.builtin").registers()<CR>')
map("n", "gr", '<cmd>lua require("telescope.builtin").lsp_references()<CR>')
map("n", "gd", '<cmd>lua require("telescope.builtin").lsp_definitions()<CR>')
map("n", "g/", '<cmd>lua require("telescope.builtin").lsp_document_symbols()<CR>')
map("n", "g?", '<cmd>lua require("telescope.builtin").lsp_workspace_symbols()<CR>')
map("n", "ge", '<cmd>lua require("telescope.builtin").lsp_document_diagnostics()<CR>')
map("n", "Db", '<cmd>lua require("telescope").extensions.dap.list_breakpoints()<CR>')
map("n", "Dcc", '<cmd>lua require("telescope").extensions.dap.commands()<CR>')
map("n", "Df", '<cmd>lua require("telescope").extensions.dap.frames()<CR>')
map("n", "Dv", '<cmd>lua require("telescope").extensions.dap.variables()<CR>')
require("plugins/telescope")
end,
})

View file

@ -0,0 +1,82 @@
local telescope = require("telescope")
local actions = require("telescope.actions")
local previewers = require("telescope.previewers")
vim.keymap.set("n", "<leader>b", '<cmd>lua require("telescope.builtin").buffers()<CR>')
vim.keymap.set("n", "<leader>f", '<cmd>lua require("telescope.builtin").oldfiles()<CR>')
vim.keymap.set("n", "<space>", '<cmd>lua require("telescope.builtin").oldfiles()<CR>')
vim.keymap.set("n", "<leader>e", '<cmd>lua require("telescope.builtin").git_files()<CR>')
vim.keymap.set("n", "<leader>g", '<cmd>lua require("telescope.builtin").git_status()<CR>')
vim.keymap.set("n", "<leader>a", '<cmd>lua require("telescope.builtin").lsp_code_actions()<CR>')
vim.keymap.set("n", "<leader>m", '<cmd>lua require("telescope.builtin").marks()<CR>')
vim.keymap.set("n", "<leader>s", '<cmd>lua require("telescope.builtin").lsp_document_symbols()<CR>')
vim.keymap.set("n", "<leader>t", '<cmd>lua require("telescope.builtin").treesitter()<CR>')
vim.keymap.set("n", "<leader>/", '<cmd>lua require("telescope.builtin").live_grep()<CR>')
vim.keymap.set("n", "<leader>.", '<cmd>lua require("telescope.builtin").file_browser()<CR>')
vim.keymap.set("n", "<leader>p", '<cmd>lua require("telescope.builtin").registers()<CR>')
vim.keymap.set("n", "gr", '<cmd>lua require("telescope.builtin").lsp_references()<CR>')
vim.keymap.set("n", "gd", '<cmd>lua require("telescope.builtin").lsp_definitions()<CR>')
vim.keymap.set("n", "g/", '<cmd>lua require("telescope.builtin").lsp_document_symbols()<CR>')
vim.keymap.set("n", "g?", '<cmd>lua require("telescope.builtin").lsp_workspace_symbols()<CR>')
vim.keymap.set("n", "ge", '<cmd>lua require("telescope.builtin").lsp_document_diagnostics()<CR>')
vim.keymap.set("n", "Db", '<cmd>lua require("telescope").extensions.dap.list_breakpoints()<CR>')
vim.keymap.set("n", "Dcc", '<cmd>lua require("telescope").extensions.dap.commands()<CR>')
vim.keymap.set("n", "Df", '<cmd>lua require("telescope").extensions.dap.frames()<CR>')
vim.keymap.set("n", "Dv", '<cmd>lua require("telescope").extensions.dap.variables()<CR>')
-- Setup
telescope.setup({
defaults = {
layout_strategy = "flex",
-- layout_defaults = {flip_columns = 160},
layout_config = {
preview_cutoff = 10,
},
mappings = {
i = {
["<CR>"] = actions.select_default + actions.center,
["<esc>"] = actions.close,
["<tab>"] = actions.add_selection,
},
},
color_devicons = true,
file_previewer = previewers.vim_buffer_cat.new,
grep_previewer = previewers.vim_buffer_vimgrep.new,
qflist_previewer = previewers.vim_buffer_qflist.new,
},
})
local layout_strategies = require("telescope.pickers.layout_strategies")
local config = require("telescope.config")
layout_strategies.flex = function(self, max_columns, max_lines)
local layout_config = self.layout_config or {}
local flip_columns = layout_config.flip_columns or 160 -- Here's why.
local flip_lines = layout_config.flip_lines or 20
if max_columns < flip_columns and max_lines > flip_lines then
self.layout_config = (config.values.layout_defaults or {})["vertical"]
return layout_strategies.vertical(self, max_columns, max_lines)
else
self.layout_config = (config.values.layout_defaults or {})["horizontal"]
return layout_strategies.horizontal(self, max_columns, max_lines)
end
end
-- Extensions
telescope.load_extension("dap")
telescope.load_extension("fzy_native")
telescope.load_extension("gh")
-- telescope.load_extension("packer") -- currently breaking packer
local M = {}
-- Pickers
M.project_files = function()
require("telescope.builtin").find_files({
cwd = require("lspconfig.util").root_pattern(".git")(vim.fn.expand("%:p")),
})
end
return M