summaryrefslogtreecommitdiff
path: root/lua/config/plugins/telescope.lua
blob: dbe844eebffedf31191963d1b45c5318479e0e5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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 open_file_appearance = vim.tbl_extend("force", grep_appearance, {
        previewer = false,
        sort_lastused = true,
        sort_mru = true,
      })

      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,
          },
          find_files = open_file_appearance,
          git_files = open_file_appearance,
          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>r", builtin.resume, { desc = "Open last telescope search" })

      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)
        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, layout_config = { height = 0.3 } })
        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, {
          git_command = { "git", "diff-tree", "--no-commit-id", "--name-only", "--diff-filter=d", "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,
  },
}