From 6b0773eb77bd3f3cd2be7a07dc2f5283b1840852 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 27 Feb 2024 23:22:11 +0000 Subject: [PATCH] Update Telescope mappings --- CHANGELOG.md | 1 + lua/opdavies/telescope/init.lua | 1 + lua/opdavies/telescope/mappings.lua | 44 +++++++++++++++++++---------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c064f31..0aa2521 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Changed +* Update Telescope keymaps to be more like the ones in . * Update Harpoon keymaps and include keymaps to remove a single file and clear all files. * Update Telescope to ignore more files and directories by default. * Replace `christoomey/vim-tmux-navigator` with `alexghergh/nvim-tmux-navigation`. diff --git a/lua/opdavies/telescope/init.lua b/lua/opdavies/telescope/init.lua index d8c8fdd..bb5e6c6 100644 --- a/lua/opdavies/telescope/init.lua +++ b/lua/opdavies/telescope/init.lua @@ -99,6 +99,7 @@ end function M.find_all_files() local opts = { + file_ignore_patterns = { ".direnv", ".git" }, no_ignore = true, prompt_title = "All Files", } diff --git a/lua/opdavies/telescope/mappings.lua b/lua/opdavies/telescope/mappings.lua index 7daf876..09e2209 100644 --- a/lua/opdavies/telescope/mappings.lua +++ b/lua/opdavies/telescope/mappings.lua @@ -1,7 +1,5 @@ TelescopeMapArgs = TelescopeMapArgs or {} -local telescope = require "telescope" - local telescope_mapper = function(key, f, options, buffer) local map_key = vim.api.nvim_replace_termcodes(key .. f, true, true, true) @@ -22,37 +20,53 @@ local telescope_mapper = function(key, f, options, buffer) end end -telescope_mapper("fb", "buffers") -telescope_mapper("fd", "find_files") -telescope_mapper("fD", "find_all_files") -telescope_mapper("fe", "file_browser") -telescope_mapper("ff", "current_buf") -telescope_mapper("fg", "git_files") -telescope_mapper("fh", "help_tags") -telescope_mapper("fl", "live_grep") -telescope_mapper("fo", "oldfiles") +-- Based on https://github.com/nvim-lua/kickstart.nvim +-- TODO: refactor telescope_mapper and add descriptions. +telescope_mapper("/", "current_buf") -- [/] Fuzzily search in current buffer +telescope_mapper("", "buffers") -- [ ] Find existing buffers +telescope_mapper("s.", "oldfiles") -- '[S]earch Recent Files ("." for repeat) +telescope_mapper("sF", "find_all_files") -- [S]earch all [F]iles +telescope_mapper("sb", "file_browser") -- [S]earch using the File [B]rowser +telescope_mapper("sf", "find_files") -- [S]earch [F]iles +telescope_mapper("sg", "git_files") -- [S]earch [G]it Files +telescope_mapper("sh", "help_tags") -- [S]earch [H]elp +telescope_mapper("sl", "live_grep") -- [S]earch using [L]ive grep +telescope_mapper("sp", "grep_prompt") -- [S]earch using grep [P]rompt local builtin = require "telescope.builtin" +local telescope = require "telescope" + local nmap = require("opdavies.keymap").nmap nmap { - "fw", + "s/", + function() + builtin.live_grep { + grep_open_files = true, + prompt_title = "Live Grep in Open Files", + } + end, + { desc = "[S]earch [/] in Open Files" }, +} + +nmap { + "sw", function() local word = vim.fn.expand "" builtin.grep_string { search = word } end, + { desc = "[S]earch for the current [W]ord" }, } nmap { - "fW", + "sW", function() local word = vim.fn.expand "" builtin.grep_string { search = word } end, + { desc = "[S]earch for the current [W]ord object" }, } -telescope_mapper("gp", "grep_prompt") - telescope_mapper("ds", "lsp_document_symbols") telescope_mapper("dl", "diagnostics")