From: Huck Boles Date: Mon, 1 May 2023 02:03:27 +0000 (-0500) Subject: fzf and rg integration into telescope X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=5921aad6673ad79c9692881d459e21909380d235;p=nvim.git fzf and rg integration into telescope --- diff --git a/lua/map.lua b/lua/map.lua index 7e729f2..ccfc248 100644 --- a/lua/map.lua +++ b/lua/map.lua @@ -42,6 +42,7 @@ vim.keymap.set('n', 'p', vim.diagnostic.goto_prev) vim.keymap.set('n', 'R', vim.lsp.buf.rename) vim.keymap.set('n', 'k', vim.lsp.buf.hover) vim.keymap.set('n', 'K', vim.diagnostic.open_float) + vim.keymap.set('n', 'd', function() if vim.g.visible_diagnostics then @@ -53,3 +54,49 @@ vim.keymap.set('n', 'd', end end ) + +-- live grep in git repo, or fall back to current repo +vim.keymap.set('n', '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', '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 +) diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 841417b..0f57f11 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -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 = { - { 'f', 'Telescope git_files' }, - { 'F', 'Telescope find_files' }, - { '', 'Telescope live_grep' }, { 'b', 'Telescope buffers' }, { '', 'Telescope command_history' }, { 'D', 'Telescope diagnostics' }, @@ -18,11 +23,23 @@ return { layout_config = { height = 0.9, width = 0.9, - } + }, + mappings = { + i = { [""] = 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 }, }