From 712de3e18237323a979b4fd256703e2edfaddf2f Mon Sep 17 00:00:00 2001 From: Volodymyr Kot Date: Fri, 23 Apr 2021 16:24:09 +0100 Subject: feat: add search history picker (#769) Co-authored-by: Volodymyr Kot --- lua/telescope/builtin/internal.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lua/telescope/builtin/internal.lua') diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index cab145d..5164245 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -297,6 +297,36 @@ internal.command_history = function(opts) }):find() end +internal.search_history = function(opts) + local search_string = vim.fn.execute('history search') + local search_list = vim.split(search_string, "\n") + + local results = {} + for i = #search_list, 3, -1 do + local item = search_list[i] + local _, finish = string.find(item, "%d+ +") + table.insert(results, string.sub(item, finish + 1)) + end + + pickers.new(opts, { + prompt_title = 'Search History', + finder = finders.new_table(results), + sorter = conf.generic_sorter(opts), + + attach_mappings = function(_, map) + map('i', '', actions.set_search_line) + map('n', '', actions.set_search_line) + map('n', '', actions.edit_search_line) + map('i', '', actions.edit_search_line) + + -- TODO: Find a way to insert the text... it seems hard. + -- map('i', '', actions.insert_value, { expr = true }) + + return true + end, + }):find() +end + internal.vim_options = function(opts) -- Load vim options. local vim_opts = loadfile(utils.data_directory() .. path.separator .. 'options' .. -- cgit v1.2.3