dotfiles/nvim/lua/telescope_config.lua

97 lines
3.0 KiB
Lua
Raw Normal View History

2022-07-03 14:30:11 +02:00
local M = {}
local hastelescope, telescope= pcall(require, "telescope")
if not hastelescope then
return M
end
2022-07-03 14:30:11 +02:00
M.git_files = function()
2023-08-25 23:37:14 +02:00
local opts = require('telescope.themes').get_ivy({})
2022-07-03 18:00:31 +02:00
opts["show_untracked"] = true
opts["layout_config"] = {height=0.2}
2022-11-19 15:08:26 +01:00
if not pcall(require"telescope.builtin".git_files, opts) then
require"telescope.builtin".find_files(opts)
end
2022-07-03 14:30:11 +02:00
end
M.project_files = function()
local opts = require('telescope.themes').get_ivy({})
opts["layout_config"] = {height=0.2}
require"telescope.builtin".find_files(opts)
end
2022-07-05 11:35:42 +02:00
M.buffers = function()
2023-08-25 23:37:14 +02:00
local opts = require('telescope.themes').get_ivy({})
2022-07-05 11:35:42 +02:00
opts["layout_config"] = {height=0.2}
require"telescope.builtin".buffers(opts)
end
2024-01-07 14:55:48 +01:00
M.fuzzyFindFiles = function()
require"telescope.builtin".grep_string({
path_display = { 'smart' },
only_sort_text = true,
word_match = "-w",
search = '',
})
end
2022-07-03 18:00:31 +02:00
local actions = require("telescope.actions")
require("telescope").setup{
defaults = {
2022-07-05 11:35:42 +02:00
file_ignore_patterns = {
2022-08-29 16:52:25 +02:00
".cache/.*",
2022-07-05 11:35:42 +02:00
"node_modules/.*",
".git/.*",
"Venv/.*",
"venv/.*",
"wandb/.*",
2023-08-25 23:37:14 +02:00
"Resources/.*",
"build/.*"
2022-07-05 11:35:42 +02:00
},
2022-07-03 18:00:31 +02:00
mappings = {
i = {
2022-07-05 11:35:42 +02:00
["jj"] = actions.close,
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
2022-07-03 18:00:31 +02:00
},
},
2024-01-07 14:55:48 +01:00
file_sorter = require'telescope.sorters'.get_fzy_sorter,
generic_sorter = require'telescope.sorters'.get_fzy_sorter,
2023-08-25 22:44:42 +02:00
},
extensions = {
undo = {
side_by_side = false,
2023-08-25 22:44:42 +02:00
layout_strategy = "vertical",
use_delta = true,
2023-08-25 22:44:42 +02:00
layout_config = {
preview_height = 0.5,
},
mappings = {
i = {
["<cr>"] = require("telescope-undo.actions").restore,
["<S-y>"] = require("telescope-undo.actions").yank_additions,
},
},
}
2024-01-07 14:55:48 +01:00
},
fzy_native = {
override_generic_sorter = false,
override_file_sorter = true,
2022-07-03 18:00:31 +02:00
}
}
2022-07-03 14:30:11 +02:00
2023-08-25 22:44:42 +02:00
telescope.load_extension("undo")
2022-07-03 14:30:11 +02:00
telescope.load_extension('fzf')
2024-01-07 14:55:48 +01:00
telescope.load_extension('fzy_native')
2022-07-03 14:30:11 +02:00
2023-08-25 22:44:42 +02:00
2023-08-25 23:37:14 +02:00
vim.keymap.set("n", "<leader>u", function() require("telescope").extensions.undo.undo() end, {noremap = true, silent = true})
vim.keymap.set("n", "<C-p>", function() require('telescope_config').git_files() end, {noremap = true, silent = true})
vim.keymap.set("n", "<C-O>", function() require('telescope_config').project_files() end, { silent = true, noremap = true })
2024-01-07 14:55:48 +01:00
-- vim.keymap.set("n", "<C-f>", function() require('telescope.builtin').live_grep{ cwd = vim.fn.systemlist("git rev-parse --show-toplevel 2> /dev/null || pwd")[1] } end, { silent = true, noremap = true })
vim.keymap.set("n", "<C-f>", function() require('telescope_config').fuzzyFindFiles() end, { silent = true, noremap = true })
2022-07-03 14:30:11 +02:00
return M