summaryrefslogtreecommitdiff
path: root/lua/config/plugins/telescope.lua
diff options
context:
space:
mode:
authorMarcelo <setanta@gmail.com>2025-03-03 21:05:55 -0300
committerMarcelo Lira <setanta@gmail.com>2025-03-07 02:15:25 -0300
commitc78361a6155dd53cd1098f7fdf33acfea20dc903 (patch)
treee13b8065c4a1180f3b1d483676b55af4cba2ee4c /lua/config/plugins/telescope.lua
Initial commit.
Diffstat (limited to 'lua/config/plugins/telescope.lua')
-rw-r--r--lua/config/plugins/telescope.lua117
1 files changed, 117 insertions, 0 deletions
diff --git a/lua/config/plugins/telescope.lua b/lua/config/plugins/telescope.lua
new file mode 100644
index 0000000..4faa22b
--- /dev/null
+++ b/lua/config/plugins/telescope.lua
@@ -0,0 +1,117 @@
+return {
+ {
+ "nvim-telescope/telescope.nvim",
+ tag = "0.1.8",
+ dependencies = {
+ "nvim-lua/plenary.nvim",
+ {
+ "nvim-telescope/telescope-fzf-native.nvim",
+ build = "make",
+ config = function()
+ require("telescope").load_extension("fzf")
+ end,
+ },
+ },
+ config = function()
+ local actions = require("telescope.actions")
+ local action_layout = require("telescope.actions.layout")
+
+ local grep_appearance = {
+ layout_strategies = "vertical",
+ theme = "dropdown",
+ layout_config = {
+ prompt_position = "bottom",
+ width = 0.7,
+ height = 0.5,
+ },
+ }
+
+ local telescope = require("telescope")
+ telescope.setup({
+ defaults = {
+ mappings = {
+ i = {
+ ["<C-h>"] = "which_key",
+ ["<C-c>"] = false,
+ ["<C-f>"] = actions.to_fuzzy_refine,
+ ["<ESC>"] = actions.close,
+ ["<M-p>"] = action_layout.toggle_preview,
+ },
+ },
+ },
+ pickers = {
+ buffers = {
+ theme = "dropdown",
+ layout_config = {
+ prompt_position = "bottom",
+ },
+ previewer = false,
+ sort_lastused = true,
+ sort_mru = true,
+ ignore_current_buffer = true,
+ },
+ live_grep = grep_appearance,
+ grep_string = grep_appearance,
+ help_tags = {
+ theme = "dropdown",
+ layout_strategies = "vertical",
+ layout_config = {
+ width = 0.7,
+ },
+ },
+ },
+ extensions = {
+ fzf = {},
+ },
+ })
+
+ local builtin = require("telescope.builtin")
+
+ vim.keymap.set("n", "<Leader>b", builtin.buffers, { desc = "List buffers" })
+ vim.keymap.set("n", "<Leader>B", function()
+ builtin.live_grep({ grep_open_files = true })
+ end, { desc = "Searches open buffers contents" })
+
+ vim.keymap.set("n", "<Leader>f", builtin.live_grep, { desc = "Search file contents" })
+ vim.keymap.set("n", "<Leader>F", builtin.grep_string, { desc = "Search for the string under the cursor" })
+
+ vim.keymap.set("n", "<Leader>m", function()
+ builtin.treesitter({
+ symbols = "function",
+ previewer = true,
+ prompt_title = "Functions",
+ prompt_prefix = "𝑓"
+ })
+ end, { desc = "Lists function names from treesitter queries", })
+
+ vim.keymap.set("n", "<Leader>o", function()
+ local ok, _ = pcall(builtin.git_files, { previewer = false })
+ if not ok then
+ builtin.find_files()
+ end
+ end, { desc = "Open a file" })
+ vim.keymap.set("n", "<Leader>O", builtin.find_files, { desc = "Open a file" })
+
+ vim.keymap.set("n", "<Leader>gf", function()
+ local ok, _ = pcall(builtin.git_status, { previewer = false })
+ if not ok then
+ builtin.find_files()
+ end
+ end, { desc = "Show files marked as modified by git." })
+ vim.keymap.set("n", "<Leader>gF", function()
+ local ok, _ = pcall(builtin.git_files, {
+ previewer = false,
+ git_command = { "git", "diff-tree", "--no-commit-id", "--name-only", "HEAD", "-r" }
+ })
+ if not ok then
+ builtin.find_files()
+ end
+ end, { desc = "Show files in the present git commit." })
+
+ vim.keymap.set("n", "<Leader>gc", "<CMD>Telescope git_commits<CR>", { desc = "Show commits" })
+ vim.keymap.set("n", "<Leader>gC", "<CMD>Telescope git_bcommits<CR>", { desc = "Show commits for the current buffer" })
+
+ telescope.load_extension("zk")
+ end,
+ },
+}