From 51638918596ed4f54fcb19abcee55edc01ed77a4 Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 16 Dec 2024 23:55:48 +0100 Subject: feat: new keymap for finding TODOs --- lua/pml68/plugins/telescope.lua | 7 +++++++ lua/pml68/remap.lua | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'lua/pml68') diff --git a/lua/pml68/plugins/telescope.lua b/lua/pml68/plugins/telescope.lua index 9c5de69..b11e28d 100644 --- a/lua/pml68/plugins/telescope.lua +++ b/lua/pml68/plugins/telescope.lua @@ -5,4 +5,11 @@ return { dependencies = { "nvim-lua/plenary.nvim" }, + opts = { + pickers = { + find_files = { + find_command = { "rg", "--files", "--hidden" }, + }, + }, + }, } diff --git a/lua/pml68/remap.lua b/lua/pml68/remap.lua index 9da8f91..92614a9 100644 --- a/lua/pml68/remap.lua +++ b/lua/pml68/remap.lua @@ -62,6 +62,28 @@ vim.keymap.set('n', 'fh', "Telescope help_tags", {}) vim.keymap.set('n', 'fz', "Telescope current_buffer_fuzzy_find", {}) vim.keymap.set('n', 'fg', "Telescope git_files", {}) vim.keymap.set('n', 'fd', "Telescope diagnostics", {}) +vim.keymap.set('n', 'ft', function() + local telescope = require("telescope.builtin") + local todo_files = {} + + local handle = io.popen("rg --files -g 'TODO.{md,txt}'") + local result = handle:read("*a") + handle:close() + + for file in result:gmatch("[^\r\n]+") do + table.insert(todo_files, file) + end + + if #todo_files > 0 then + telescope.find_files({ + prompt_title = "Choose TODO file", + cwd = vim.fn.getcwd(), + search_dirs = todo_files + }) + else + telescope.grep_string({ search = "TODO" }) + end +end, { noremap = true, silent = true }) -- Diagnostics, LSP vim.keymap.set('n', 'gl', 'lua vim.diagnostic.open_float()') -- cgit v1.2.3