]> git.huck.website - nvim.git/commitdiff
fzf and rg integration into telescope
authorHuck Boles <huck@huck.website>
Mon, 1 May 2023 02:03:27 +0000 (21:03 -0500)
committerHuck Boles <huck@huck.website>
Mon, 1 May 2023 02:03:27 +0000 (21:03 -0500)
lua/map.lua
lua/plugins/telescope.lua

index 7e729f2fd3a1eb1f4f384b9c29eec5606d3c952e..ccfc24819d9546cde944ccf3000dffa93cfe2f6f 100644 (file)
@@ -42,6 +42,7 @@ vim.keymap.set('n', '<leader>p', vim.diagnostic.goto_prev)
 vim.keymap.set('n', '<leader>R', vim.lsp.buf.rename)
 vim.keymap.set('n', '<leader>k', vim.lsp.buf.hover)
 vim.keymap.set('n', '<leader>K', vim.diagnostic.open_float)
+
 vim.keymap.set('n', '<leader>d',
     function()
         if vim.g.visible_diagnostics then
@@ -53,3 +54,49 @@ vim.keymap.set('n', '<leader>d',
         end
     end
 )
+
+-- live grep in git repo, or fall back to current repo
+vim.keymap.set('n', '<leader>F',
+    function()
+        local function is_git_repo()
+            vim.fn.system("git rev-parse --is-inside-work-tree")
+
+            return vim.v.shell_error == 0
+        end
+
+        local function get_git_root()
+            local dot_git_path = vim.fn.finddir(".git", ".;")
+            return vim.fn.fnamemodify(dot_git_path, ":h")
+        end
+
+        local opts = {}
+
+        if is_git_repo() then
+            opts = {
+                cwd = get_git_root(),
+            }
+        end
+
+        require("telescope.builtin").live_grep(opts)
+    end
+)
+
+vim.keymap.set('n', '<leader>f',
+    function()
+        local function is_git_repo()
+            vim.fn.system("git rev-parse --is-inside-work-tree")
+            return vim.v.shell_error == 0
+        end
+        local function get_git_root()
+            local dot_git_path = vim.fn.finddir(".git", ".;")
+            return vim.fn.fnamemodify(dot_git_path, ":h")
+        end
+        local opts = {}
+        if is_git_repo() then
+            opts = {
+                cwd = get_git_root(),
+            }
+        end
+        require("telescope.builtin").find_files(opts)
+    end
+)
index 841417b0c8527a1e6e3f5a61c50d79a169afc160..0f57f114d3df33520cc614a19a6c076b3687da8c 100644 (file)
@@ -1,11 +1,16 @@
 return {
     {
         'nvim-telescope/telescope.nvim',
-        dependencies = { 'nvim-lua/plenary.nvim' },
+        lazy = false,
+        dependencies = {
+            'nvim-lua/plenary.nvim',
+            {
+                'nvim-telescope/telescope-fzf-native.nvim',
+                build = {
+                    'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' }
+            },
+        },
         keys = {
-            { '<leader>f',     '<CMD>Telescope git_files<CR>' },
-            { '<leader>F',     '<CMD>Telescope find_files<CR>' },
-            { '<leader><C-f>', '<CMD>Telescope live_grep<CR>' },
             { '<leader>b',     '<CMD>Telescope buffers<CR>' },
             { '<leader><C-r>', '<CMD>Telescope command_history<CR>' },
             { '<leader>D',     '<CMD>Telescope diagnostics<CR>' },
@@ -18,11 +23,23 @@ return {
                     layout_config = {
                         height = 0.9,
                         width = 0.9,
-                    }
+                    },
+                    mappings = {
+                        i = { ["<ESC>"] = require('telescope.actions').close },
+                    },
                 },
                 pickers = {},
-                extensions = {},
+                extensions = {
+                    fzf = {
+                        fuzzy = true,
+                        override_generic_sorter = true,
+                        override_file_sorter = true,
+                        case_mode = 'smart_case',
+                    }
+                },
             }
+
+            require('telescope').load_extension('fzf')
         end
     },
 }